foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.09k stars 129 forks source link

Support validatedWith with nested property of a field's value #611

Closed riceyeh closed 2 years ago

riceyeh commented 2 years ago

validatedWith is used for validation of a field with other attributes beyond its value. I suggest to extend validatedWith to support nested property of field's value. The following is an example:

it('same oid', (done) => { const fields = [ "f1", "f2" ] const values = { f1: { oid: 1, name: 'Object 1' }, f2: { oid: 1, name: 'Object 1.1' } } const rules = { f1: 'different:f2', f2: 'different:f1' } const validatedWith = { f1: 'value.oid', f2: 'value.oid' } const related = { f1: ['f2'], f2: ['f1'] }

const $form = new Form({fields, values, rules, validatedWith, related}, { plugins, name: 'form'})

$form.validate({showError: true}).then(({isValid}) => { expect(isValid).to.be.false done() })

})

foxhound87 commented 2 years ago

nice, I have published a new version!