4
Vote

RequiredIf clientside validation doesn't work for enums with radio buttons

description

If you are using a RequiredIf attribute and you want to check this against an enum it doesn't seem to work correctly as the test value is the integer value of the enum, whereas the value from the radio button is the string value of the enum.
 
These are then generally different so the validation fails.
 
This may well affect other input types apart from radio buttons, but that's where I had the issue.

comments

i8beef wrote May 11, 2012 at 7:34 PM

I'm not sure if this is related or not, but I've noticed that if you do something like a RequiredIf EqualTo comparison against an Enum, that the client side script will attach a validator based on the Enum name instead of the value specified... So if I have Enum.Pending, Enum.Accepted, etc. which I am comparing against, the server side correctly evaluates these to 0, 1, etc., but the client side has the dependentvalue set to "Pending" or "Accepted" instead of "0" or "1" like it should...

This may be in opposition to this item as well, if radio boxes work differently or something...

MehCFL wrote Jun 25, 2012 at 11:51 AM

I think that is the same issue.