question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formsy onChange model missing value object methods

See original GitHub issue

Hi,

For context I have created a datepicker using withFormsy(). The date selected by the user is a Moment.js object which has a bunch of methods for manipulating and formatting the date.

The model on the Formsy prop onChange((model)=>{ }) remove all the __proto__ methods on the object.

I think this is down to the cloneIfObject() method in https://github.com/formsy/formsy-react/blob/6fcc682e1dae82dd5643a744f587713f4d8a9ced/src/utils.ts#L47 which is spreading the current model values.

This doesn’t seem to be the same behaviour with setting the value using the setValue() prop in the withFormsy component.

This was working pre the v1 to v2 update.

Is the cloneIfObject method needed?

Many thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wkerswell-greshamcommented, Feb 7, 2020

After some playing yesterday I have worked around it by using the model value to create another moment object.

  const onChange = ({date}) =>{
      if(date){
        const momentDate = moment(date);
        ...
      }
  }

Makes sense what you are saying about only supporting the JSON so happy for this issue to be closed. Thanks

1reaction
rkuykendallcommented, Feb 6, 2020

image

It doesn’t appear so. I’m going to write a test-case to get more definitive information.

Also, one additional option is that objects like this just shouldn’t be supported. In that case, you would want to use something like an ISO 8601 string as your actual “value” and either use moment only internally in your input component, only external to the form, or in both. What do you think about that?

There’s some sense in formsy only supporting things that could be sent to or from a server as JSON.

Read more comments on GitHub >

github_iconTop Results From Across the Web

formsy-react/API.md at master - GitHub
"onChange" triggers when setValue is called on your form elements. It is also triggered when dynamic form elements have been added to the...
Read more >
How to can I use onChange on React Hook Form Version 7.0
For those new to this thread, the problem with just adding onChange is that in RHF v7.x calling ...register('name') spreads an object containing ......
Read more >
Set Control Value/Text OnChange - Power Platform Community
Solved: Could we please have the ability to set a control value based on the change of another control? Example: TEXTBOX1: Enter your...
Read more >
SCR19: Using an onchange event on a select element ... - W3C
The objective of this technique is to demonstrate how to correctly use an onchange event with a select element to update other elements...
Read more >
useForm | React Hook Form - Simple React forms validation
Their default values should be an empty object. For example: {} . The keys of the error object should match the name values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found