I have the following model:
public class Customer
{
public string FirstName {get;set;}
public string LastName {get; set;}
[Remote("CardExisting", "Validation", AdditionalFields="FirstName,LastName")
public string CardNumber {get; set;}
}
CardExisting action will check that there is an existing record for the combination of cardNumber for the firstName and LastName.
What if user will first enter the card number and then his name, I cant validate him, so when he returns and input his name I need to remote validate again, how can I do that when focus was already lost from cardnumber property?
The way I have got this working is by adding some JavaScript.
So when the first name is changed you clear any previous values from the card number and re-validate the card number.
Following on from Chris's helper method above. This works great in most instances, but if your model has a prefix at all e.g. 'Custom.Address.Line1' . The additional fields are not found correctly. I have updated the helper with some additional logic from the jquery.validate.unobstructive lib which will lookup the fields correctly.
if you don't like to create client scripts:
And validate in CardExisting all fields are filled or not
Expanding on Jaluka's answer, I wrote this helper method that finds each remotely validating element that has "additional fields," and then causes validation on said element to fire each time one of those fields changes.
Call the function like so: