frig-js / frig

Simple but powerful forms for React. Inspired by SimpleForm. https://frig-js.github.io/frig
MIT License
10 stars 2 forks source link

Remove validations from Frig #103

Open jbinto opened 8 years ago

jbinto commented 8 years ago

We would like to remove validations from Frig.

There are two types of errors/validations in Frig:

As for "Frig validations", users don't have a lot of control over these. We provide three very basic validations, required, min, and max. 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's onSubmit 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, but Form's props.errors would be empty.


We propose removing validations entirely, requiring consumers of Frig to implement their own custom validation in the onChange and onSubmit handlers.

Pros:

Cons:

SpiritBreaker226 commented 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.

jbinto commented 8 years ago

Some early (non-binding!) thoughts on how this could work:

Option 1:

Option 2:

More ideas re: option 2:

{
  presence: (v) => v != null,
  min: (v, min) => v > min,
  max: (v, max) => v < max,
  fizzbuzz: (v) => v % 5 == 0 && v % 3 == 0,
}

Potential challenges: