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

Mobx form textfield default value not recognized on submit #586

Closed prajeeshbs closed 2 years ago

prajeeshbs commented 2 years ago

The code is as follows

<TextField {...form.$("phone.countryCode").bind()} value={222} /> The form setup is as follows

{
        name: "phone",
        fields: [
          {
            name: "countryCode",
            label: "Country Code:",
            bindings: "TextField",
            placeholder: "+",
            rules: "required",
          }
       ]
}

The value displays correctly in the textfield. But when i submit the form, it shows "required" error.

Is assume field.input.onChange is not triggered when we set the value like this and hence the mobx field is not updated with the value.

Any idea on how to fix this?

foxhound87 commented 2 years ago

you have to pass the value to the field definition or by using the update/set/bind methods, not passing it directly to the component.