jonsamwell/angular-auto-validate

Validate hidden fields on save

Closed this issue · 9 comments

A form I have has two tabs within it. The Entire form is/must be submitted at once. I validate on save, however angular-auto-validate does not validate hidden fields by design. Initially I assume this was impossible because the DOM elements don't exist. I had issues calling validate form on the individual form elements (after making visible of coarse). However this actually works fine.

It would be great to have it validate all fields. Perhaps by default with a user config; or even just a config option. User's with hidden fields could add a property to those fields.

What are your thoughts?

Ended up validating the sub form on tab change. So i don't need this fix (at least yet). Still an idea though. :)

I'll make this an attribute of the form i.e. validate-hidden-fields

Yea this is important when you have widgets that wrap the input element and hide the original element a la Kendo UI

Are we talking about hidden fields

<input type="hidden" />

or

<input type="text" style="display:none;" />

or both?

Personally I've only needed it when the display: none or visibility: hidden but if it's not too complicated to support both, then both. You never know when your next widget decides to use type="hidden". While we are at it, maybe make the directive also work on a control by control basis like maybe validate-always, so that we can have an override in case we need to mix and match or have the validate-hidden-fields takes a function callback with the element as a param that returns true or false

@lcornejo Same; I'm using ng-show which sets display: none. But there should definitely be some thought put into the type="hidden". From my experience that is used mostly for anti-spam measures. You pass some arbitrary field that you expect to be blank because it's not visible. If it isn't it's safe to assume a bot filled out the form.

So perhaps the default should be not to address those fields nut to provide a directive to force those fields to validate? Or is that too confusing/counter intuitive...?

It might be I know angular doesn't bind to type="hidden" so the validation of this might be tricky.

Hmm perhaps it's best to ignore them like angular does...

This is now added (docs to follow).

Add this attribute to the parent form or ng-form to validate non visual elements:

<form role="form" name="testFrm" novalidate="novalidate"
                  ng-submit="submit();"
                  validate-non-visible-controls>