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

form.update() does not consider input function #514

Closed riceyeh closed 5 years ago

riceyeh commented 5 years ago

The following example shows form.update() does not consider input function.

const fields = [
  'priority',
  'itineraryItems[].hotel.name',
  'itineraryItems[].hotel.starRating',
];

const input = {
  'priority': p => p === '' ? -1 : Number(p),
  'itineraryItems[].hotel.starRating': rate => {
    return Number(rate)
  }
}

class NewForm extends Form {
  hooks() {
    return {
      onInit(form) {
        form.update({
          priority: '1',
          itineraryItems: [{
            hotel: {
              name: 'Shangri-La Hotel',
              starRating: '5.0',
            },
          }, {
            hotel: null,
          }, {
            hotel: {
              name: 'Trump Hotel',
              starRating: '5.0',
            },
          }],
        });
      },
    };
  }
}

const form = new NewForm({ fields, input }, { name: 'Form 998' });

describe.only('number rating', () => {
  it('', () => {
    expect(form.$('priority').value).to.be.equal(1) // fails, it is still '1'
    expect(form.$('itineraryItems.0.hotel.starRating').value).to.be.equal(5) // fails, it is still '5'
  })
});
foxhound87 commented 5 years ago

:tada: This issue has been resolved in version 2.0.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: