aspnet-client-validation icon indicating copy to clipboard operation
aspnet-client-validation copied to clipboard

Should not validate disabled fields

Open lonix1 opened this issue 1 year ago • 8 comments

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.

lonix1 avatar Jan 01 '24 17:01 lonix1

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)

lonix1 avatar Jan 01 '24 17:01 lonix1

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.

dahlbyk avatar Jan 01 '24 21:01 dahlbyk

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.

lonix1 avatar Jan 02 '24 02:01 lonix1

I found another use case that differs from jQuery walidate:

When a fieldset is disabled, it ignores all fields within.

lonix1 avatar Jan 02 '24 02:01 lonix1

TL;DR

Summary of incompatibilities between the libraries:

  • should ignore fields (input, select, textarea) which are disabled
  • should ignore all fields within a disabled fieldset
  • disabled fields' values should not be included when submitted with remote

lonix1 avatar Jan 02 '24 02:01 lonix1

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?

haacked avatar Jan 02 '24 20:01 haacked

  • 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.

haacked avatar Jan 02 '24 20:01 haacked

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 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.

In a dynamically generated form that doesn't happen - all fields in the fieldset will be validated whether you want that or not.

lonix1 avatar Jan 03 '24 03:01 lonix1

I have the same need as @lonix1. This is the last feature I lack to fully migrate to this library.

TanguyPa avatar Mar 01 '24 16:03 TanguyPa