aspnet-client-validation
aspnet-client-validation copied to clipboard
Should not validate disabled fields
The jQuery Validate plugin does not validate fields with the disabled attribute. However this library does.
If this library's purpose is to be a drop-in replacement, then one could argue this is a bug.
Is there a workaround for this? I tried, without success:
- toggling the field's
disabled - toggling the field's
data-val="true" - calling
v.scan(form)
If this library's purpose is to be a drop-in replacement
It is!
then one could argue this is a bug.
It is! Probably pretty easy to demo/fix, if you'd like to give it a try.
A related bug is that disabled inputs' values are probably included when submitted with remote.
I did have a look but am unfamiliar with the code so couldn't figure out what was going on. :blush:
Decided to at least post the bug report so it's being tracked. I'm not using remote validators so cannot confirm that use case.
I found another use case that differs from jQuery walidate:
When a fieldset is disabled, it ignores all fields within.
TL;DR
Summary of incompatibilities between the libraries:
- should ignore fields (
input,select,textarea) which aredisabled - should ignore all fields within a disabled
fieldset - disabled fields' values should not be included when submitted with
remote
What's an example where this comes into play for you? For example, if a field is required on the server, but disabled on the client, what do you expect to happen?
- should ignore all fields within a disabled
fieldset
I think this we get for free because the browser will disable the submit buttons and all the inputs so validation won't happen. Correct me if you have a scenario where this doesn't work.
Simple use case:
A complex form generated dynamically at runtime (by javascript). Some fields must be enabled/disabled to control whether they are submitted; if not done then all fields would be submitted which leads to errors on the server side.
In fact any complex form (not simple CRUD) may have complex interactions which will fail due to this. I imagine there are other use cases which I've not encountered yet too.
The jQuery Validation plugin works this way, but when porting code to this library it fails.
- should ignore all fields within a disabled
fieldsetI think this we get for free because the browser will disable the submit buttons and all the inputs so validation won't happen. Correct me if you have a scenario where this doesn't work.
In a dynamically generated form that doesn't happen - all fields in the fieldset will be validated whether you want that or not.
I have the same need as @lonix1. This is the last feature I lack to fully migrate to this library.