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

validation it kick off onBlur for initially empty values #104

Open
takaczapka opened this issue Feb 5, 2018 · 1 comment
Open

validation it kick off onBlur for initially empty values #104

takaczapka opened this issue Feb 5, 2018 · 1 comment

Comments

@takaczapka
Copy link

Consider a following validation (field "bar" string |> andThen nonEmpty).

Initial value for the field is empty, but I would like the validation to kick off onBlur. So if user types something and later deletes it, she gets a validation error.

At the moment validation is only shown when the form is submitted or the field has some initial value.

Reading the source and it looks it's not possible at the moment. The definition of changed fields would need to get bumped for on blured fields. Or another field facet added to get this scenario handled.

To recreate:
use example https://github.com/etaque/elm-form/tree/master/example . If you change initial value for name field from hey to empty and recompile it you'll see that name validation is not happening onBlur anymore.

@dtraft
Copy link

dtraft commented May 25, 2018

Hi @takaczapka, I could be wrong, but it appears this is related to updates from #95.

In that pull request, fields that match their original value after update are removed from the set of changed fields. Since the current getLiveError function will only surface errors where the corresponding field is a member of the changed fields set, it is missing this scenario.

@etaque - Could the getLiveError function be updated to use the dirty tracking instead of the changed fields tracking? If we simply removed the code which removes the field from the dirty set on Blur and then update the getLiveError conditional from this:

isSubmitted form || (isChangedAt name form && not (isDirtyAt name form))

to this:

isSubmitted form || isDirtyAt name form

Would that have impacts on other functionality? I am happy to post a PR, just wanted to check my approach first :)

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

No branches or pull requests

2 participants