I want to use Xval to validate two elements e.g.
DropDown: << Not In List is selected by user >>
Textbox: <<A value must be entered into the text box >>
I can easily detect that the value for "Not in List" is selected (or not) in the drop down. However, how to now check the value in the texbox?
I've tried the following by adapting the BookingsDemo... To simulate the problem Im checking the booking name against the number of guests. If the booking name is "a" the the number of guests cannot be 0 (e.g. if Not in List is selected in the
dropdown then the texbox cannot be blank). So Ive added the following code to check the condition
public static IEnumerable ValidateName(Booking booking)
if (booking.Name == "a" && booking.NumGuests == 0)
yield return new ErrorInfo("Name", "There must be people in your group");
... and in my .aspx file Ive wired up both the Name and the NumGuests to the validation as follows....
<%= Html.ClientSideValidation("booking", typeof(Booking))
.AddRule("BookingDate", new RemoteRule(Url.Action("ValidateBookingDate")))
.AddRule("Name", new RemoteRule(Url.Action("ValidateName")))
Here lies the problem...
1. By tabbing out of either Name I get an error message as required if the number of guests is not equal to zero. This is correct behaviour.
2. I then go into number of guests and change the value to e.g. 5.
This does then not clear the validation on Name and I cannot submit the form.
Any ideas how I can either..
a) Clear the validation on Name after I have entered the number of guests. Or...
b) Force revalidation before form submission
Thanks in advance for all responses received.
(I'm using xVal 1.0)