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

fix(base.ts): fix form defaults() #624

Closed mmoczulski closed 1 year ago

mmoczulski commented 1 year ago

It seems to me, that there was a bug introduced with commit https://github.com/foxhound87/mobx-react-form/commit/26123aa7718871c6e9ddec67e1699e949d096ece#diff-65addcde6fff5229abdf5708736cabd07f335e865002080cd102d2fbb3ec67a8R865.

Today I have updated mobx-react-form in my project from version 3.2.0 to 6.1.0 and noticed a problem with default values, which now became an empty object. After digging in lib code I have found the culprit in the commit mentioned above.

My form was defined like this (simplified):

const fields = ['type', 'from', 'to'];
const defaults = {
  type: 'INVOICES',
  from: '2023-01-01',
  to: '2023-12-31',
};

class ReportingForm extends Form {}

export default new ReportingForm({ fields, defaults });

and running following code:

const defaults = ReportingForm.defaults();

returned an empty object.

foxhound87 commented 1 year ago

Thank you for the fix and test case, it was my mistake during refactoring! I will release it asap

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 6.1.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: