ember-validated-form icon indicating copy to clipboard operation
ember-validated-form copied to clipboard

Make setDirty more clever

Open makepanic opened this issue 6 years ago • 3 comments

Right now setDirty always sets the dirty property to true. We could make it more clever to only dirty the form if the changeset isDirty is true.

This also helps to prevents validating the form when removing focus of a form that uses autofocus to focus the first input element.

If you're fine with this solution, I could open a PR.

makepanic avatar Feb 26 '18 15:02 makepanic

Hi @makepanic, that would mean that focussing and un-focussing an input element without changing it wouldn't mark it dirty, right? I think that's not great for UX - for example, you wouldn't immediately see required field validations anymore.

czosel avatar Feb 26 '18 17:02 czosel

I guess you're right that it doesn't make sense for all forms.

For our case we have a form that takes focus and only validates when changing the value or once it's submitted. Required fields are visually marked and simply focus/blur isn't triggering the validation.

I guess we can close this issue as it's possible to create a validated-input component and simply overwrite the default setDirty implementation to use model.isDirty.

makepanic avatar Feb 26 '18 20:02 makepanic

Alright - i'll leave the issue open for a bit anyway. If there's more demand for something like this we could consider adding an option.

czosel avatar Feb 27 '18 08:02 czosel