Open jbinto opened 8 years ago
Loss of declarative validations, e.g.
<Input type="number" min="10" max="20" />
Not necessary because the validation could still happen, on the theme side, where all of the components could have individual validation. For example, the Number component could have a min and max validation, on its value, then display an error using the themes error list component.
Some early (non-binding!) thoughts on how this could work:
Form.onSubmit
(or Form.onChange
), completely ad-hoc, with no mention of validation.validate
hook on <Input>
and <Form>
<Input>
, validate
would have a default implementation (defaultProps
) as () => true
<Form>
, validate
would have a default implementation (defaultProps
) that returns true if all inputs validate, and false if any input fails to validate submit
handler, we won't call user-provided onSubmit
unless all validate
hooks return trueMore ideas re: option 2:
validate
callback would have a signature of (data)
.validate
callback might have a signature like (value, data)
. Most field-level validation would be done simply on value
, but in the case of interdependent fields (e.g. password confirm) you might need access to the entire tree.{
presence: (v) => v != null,
min: (v, min) => v > min,
max: (v, max) => v < max,
fizzbuzz: (v) => v % 5 == 0 && v % 3 == 0,
}
Potential challenges:
props.data
and props.onChange
. A parent component is responsible for storing data
somewhere (component local state, Redux store, etc) and also for updating it when Frig calls onChange
.props.errors
, which is currently intended for use with server-side errors.
onError
hook to <Form>
, which behaves just like onChange
Form.props.errors
props.errors
. It would be the parent component's choice/responsibility to either merge with existing (e.g. server-side) errors, or to overwrite them.frigging-redux
to tie this all together.
We would like to remove validations from Frig.
There are two types of errors/validations in Frig:
<Form errors={}>
attribute, typically server-side errors (but could be anything)As for "Frig validations", users don't have a lot of control over these. We provide three very basic validations,
required
,min
, andmax
. There is no support for custom validations."Frig validations" run in a way that is inconsistent with the
<Form errors={}>
attribute.When a field changes, we run these validations. If there is an error, we display the error message next to the field.
<Submit>
will simply refuse to call Form'sonSubmit
if there are any errors.There is no way to programatically access or manipulate these field-level, client-side errors. They also don't cascade up to the
<FormErrorList>
object. A form may have 10 (client side) invalid fields, butForm
'sprops.errors
would be empty.We propose removing validations entirely, requiring consumers of Frig to implement their own custom validation in the
onChange
andonSubmit
handlers.Pros:
<FormErrorList/>
Cons:
<Input type="number" min="10" max="20" />