Open fabienjuif opened 5 years ago
or get.validate
? get
alone will not do validation ?
const loginValues = form('login').get()
const loginValues = form('login').get.validate()
const name = form('login').get.validate('name') // feel odd
I think we can pass the validator on second function props .
const loginValues = form('login').get(([value, validator]) => {})
const loginValues = form('login').get('name', (value, validator) => {})
with middleware support
// test inputs (required/pattern)
const loginValues = form('login').get()
// test input "name" (required/pattern)
const name = form('login').get('name')
// test inputs (required/pattern + validator)
// - doesn't call the internal validator
const loginValues = form('login').get((values, next) => {
if (values.name.length > 10) return true
return { name: 'wrong_length' }
})
// - call the internal validator
const loginValues = form('login').get((values, next) => {
if (values.name.length > 10) return [{ name: 'wrong_length' }, ...next(values)]
return true
})
// test input "name" (required/pattern + validator)
const name = form('login').get('name', value => {
if (value.length > 10) return true
return 'wrong_length'
})
metadata
storeget
(as a callback)required
andpattern
required
andpattern
get should returns
undefined
if tests failed, anderrors
store is filled with errorsto set metadata: