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

[react] value doesn't update on the component #92

Closed
periabyte opened this issue Aug 28, 2016 · 7 comments
Closed

[react] value doesn't update on the component #92

periabyte opened this issue Aug 28, 2016 · 7 comments
Assignees
Labels

Comments

@periabyte
Copy link

periabyte commented Aug 28, 2016

component value doesn't update after setting the state (which is passed to props as value)
here's a jsfiddle( https://jsfiddle.net/w6w30Lv7/) to show the bug.

@nosir nosir added the bug label Aug 29, 2016
@nosir nosir self-assigned this Aug 29, 2016
@nosir
Copy link
Owner

nosir commented Aug 29, 2016

Thanks, let me have a look at this.

@cht8687
Copy link
Collaborator

cht8687 commented Aug 30, 2016

@periabyte The fiddle link mark down seems not working properly. should be jsfiddle

@nosir
Copy link
Owner

nosir commented Aug 30, 2016

@cht8687 cheers, I edited it, fine now

@nosir
Copy link
Owner

nosir commented Aug 30, 2016

Fix applied, some explanation for the fix:

Inside the cleave component, no doubt input.value is bound to the value state, however, this only happens internally, the state can't be shared with parent components.

In the fix, I added a setRawValue method, which works same as the plain JS one.

Check this: https://jsfiddle.net/nosir/wqm8pm6c/

If you need to update/reset the cleave field value from model, this is the way:

  1. Pass onInit to component, the callback returns the cleave instance, store it as a variable or in state.
  2. Whenever you want to update value, call cleave.setRawValue('...') to trigger the change.
  3. onChange event will be automatically triggered, from here you can grab the returned raw/formatted value and update your state.

@cht8687
Copy link
Collaborator

cht8687 commented Sep 7, 2016

If you put a $ sign on onInit, this really likes Angular component lifecycle now....lol

@nosir
Copy link
Owner

nosir commented Sep 8, 2016

Will close this, please reopen if there is any issue.

@nosir nosir closed this as completed Sep 8, 2016
@nosir
Copy link
Owner

nosir commented Jan 15, 2017

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

No branches or pull requests

3 participants