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

Field event handlers not called when form events are triggered. #562

Closed Nodios closed 3 years ago

Nodios commented 3 years ago

If you register onReset event handler on a field and then trigger form.onReset, field value is reset to but the field event handler is not called.

Is this by design?

foxhound87 commented 3 years ago

please can you make a codesandbox with this issue?

Nodios commented 3 years ago

@foxhound87 here: https://codesandbox.io/s/objective-colden-zn25m

foxhound87 commented 3 years ago

I can see that the hooks are called correctly

Nodios commented 3 years ago

No, look at the question.

If you click on form reset, should field onReset hook be called?

foxhound87 commented 3 years ago

No, it should not be called, but I don’t see strange behavior

Nodios commented 3 years ago

You said it should be called, but it is not. This is a bug then.

foxhound87 commented 3 years ago

Sorry, I misunderstood the question. The fields has their own onReset handler which calls the onReset hook on the field. Actually you have to call field.reset() (or field.onReset) on the form onReset handler for each filed you need.

Nodios commented 3 years ago

I got that correct. This what is depicted in the example. Okay, that pretty much solves it for me. It is by design :)

foxhound87 commented 3 years ago

you can easly achieve it:

        hooks: {
          onReset: (form) => {
            console.log("Form 'onReset' called");
            form.each((field) => field.onReset(new CustomEvent('onReset')));
          }
        }
Nodios commented 3 years ago

Yes, I am aware of that. Thank you