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.
// I hate naming things
function initializeRemotelyValidatingElementsWithAdditionalFields($form) {
var remotelyValidatingElements = $form.find("[data-val-remote]");
$.each(remotelyValidatingElements, function (i, element) {
var $element = $(element);
var additionalFields = $element.attr("data-val-remote-additionalfields");
if (additionalFields.length == 0) return;
var rawFieldNames = additionalFields.split(",");
var fieldNames = $.map(rawFieldNames, function (fieldName) { return fieldName.replace("*.", ""); });
$.each(fieldNames, function (i, fieldName) {
$form.find("#" + fieldName).change(function () {
// force re-validation to occur
$element.removeData("previousValue");
$element.valid();
});
});
});
}
Call the function like so:
$(document).ready(function() {
initializeRemotelyValidatingElementsWithAdditionalFields($("#myFormId"));
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…