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

add new optional convertValue property to FormsyText #220

Merged
merged 1 commit into from
Jul 19, 2017

Conversation

ulich
Copy link
Contributor

@ulich ulich commented Jun 23, 2017

When using a FormsyText with type="number" for example, the controlled value is
still a string. By specifying a convertValue function, you can convert the value to a number,
before it gets passed to formsy's setValue() for example.

Another example: a user enters the numbers of seconds, and internally it is converted to milliseconds

<FormsyText name="millis" value={millis / 1000} convertValue={(v) => Number(v) * 1000}` />

The whole thing can be probably applied to a wide range of use cases

When using a FormsyText with type="number" for example, the controlled value is
still a string. By specifying a convertValue function, you can convert the value to a number,
before it gets passed to formsy's setValue() for example.
@ryanblakeley ryanblakeley merged commit d76f036 into formsy:master Jul 19, 2017
@ulich ulich deleted the number branch July 20, 2017 06:00
@ulich
Copy link
Contributor Author

ulich commented Jul 20, 2017

thanks! when do you plan to create a new release?

@ryanblakeley
Copy link
Collaborator

It's out now, v0.6.1.

@ryanblakeley
Copy link
Collaborator

Hey just want to note thanks for this PR. I'm putting it to use already!

It seems like it might be good to force the conversion to happen before sending the value into validations. Do you have any thoughts on that? Would there be a reason to keep those operations separate? Right now I'm duplicating some conversion logic in my convertValue prop and a custom validation function. My first thought it that the conversion should happen, then validate the output. Is there a reason that would not be a good idea?

@ulich
Copy link
Contributor Author

ulich commented Jul 26, 2017

Sounds sane yeah. I dont see any issues with that 👍

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

Successfully merging this pull request may close these issues.

2 participants