Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Conditional validation #64

Closed
mingan opened this issue Nov 26, 2016 · 4 comments
Closed

Conditional validation #64

mingan opened this issue Nov 26, 2016 · 4 comments

Comments

@mingan
Copy link

mingan commented Nov 26, 2016

Is it possible to validate a field only if another field has a specific value, e.g. don't validate e-mail if the user prefers to be contacted by a phone?

@etaque
Copy link
Owner

etaque commented Nov 26, 2016

Yes, you can use andThen for that, see gist from this issue:
#49 (comment)
https://gist.github.com/nmk/e9fd97dd1a62c04fc52545fec5a9b4ef#file-main-elm-L70-L84

That said, I think I should remove validate from model and ask it on Form.update, that would allow to generate the validation from current model, be it form or other fields.

@etaque etaque closed this as completed Nov 26, 2016
@igray
Copy link

igray commented Nov 30, 2016

I'd like to +1 on asking for validate on Form.update. This would also provide for server-side validation, which seems to be alluded to here but couldn't actually work because you can't pass in any current context into that method. Unless I'm missing something?

@etaque
Copy link
Owner

etaque commented Nov 30, 2016

You're not missing anything, this asyncCheck function is useless!
I'm pretty much sold on the validate in Form.update, just need to decide when I'll do that. I already did a major release a few weeks ago for 0.18, but hey, version numbers are cheap :)

@etaque
Copy link
Owner

etaque commented Dec 16, 2016

FYI validation has been removed from model in master, release coming soon.

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

No branches or pull requests

3 participants