Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
riceyeh opened this issue Aug 31, 2019 · 1 comment
Closed

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

riceyeh opened this issue Aug 31, 2019 · 1 comment

Comments

@riceyeh
Copy link
Contributor

riceyeh commented Aug 31, 2019

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'
  })
});
riceyeh added a commit to riceyeh/mobx-react-form that referenced this issue Sep 1, 2019
riceyeh added a commit to riceyeh/mobx-react-form that referenced this issue Sep 1, 2019
riceyeh added a commit to riceyeh/mobx-react-form that referenced this issue Sep 1, 2019
@foxhound87
Copy link
Owner

🎉 This issue has been resolved in version 2.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants