asyncRule
Specification
Definition
type AsyncRule = (params) => AsyncRulePayloadtype AsyncRulePayload = {
valid: boolean,
extra?: {
[exraKey: string]: any
}
}Parameters
Example
Last updated
type AsyncRule = (params) => AsyncRulePayloadtype AsyncRulePayload = {
valid: boolean,
extra?: {
[exraKey: string]: any
}
}Last updated
import React from 'react'
import { Form } from 'react-advanced-form'
import { Input } from 'react-advanced-form-addons'
export default class Example extends React.Component {
validateUsername = ({ value, fieldProps, fields, form }) => {
return fetch('https://check.if/user/exists', {
method: 'POST',
body: JSON.stringify(value),
})
.then(res => res.json())
.then((res) => {
const { statusCode } = res
return {
valid: (statusCode === 'SUCCESS')
}
})
}
render() {
return (
<Form>
<Input
name="username"
asyncRule={this.validateUsername} />
</Form>
);
}
}