0
marble68 created
I have a checkbox on an entity CreateOrEdit modal, and if it's changed, I need to make one of the inputs required (change the rules).
In the _CreateOrEditModal.js file's init event - I'm doing this:
_$manualCleared = _modalManager.getModal().find('input[name=wasManuallyCleared]'); // $('#wasManuallyCleared]');
_$manualCleared.change(function (e) {
console.log('clear checked');
console.log(e);
// if this is set, Taker_wasManuallyClearedReason is required.
$("#Taker_wasManuallyClearedReason").rules("add", {
required: true,
minlength: 2,
messages: {
required: "This field is required",
minlength: jQuery.validator.format("More than {0} characters are necessary")
}
})
});
Thanks for any advice.
1 Answer(s)
-
0
For anyone wondering - this in the right place - but I was doing it wrong.
The key is to add rules at the end of the init function, after .validate() is called.
I'm still not sure this is the best place, as I fear my rules will be dumped on an entity regen.
This worked:
_$takerInformationForm.validate(); $("#Taker_wasManuallyClearedReason").rules("add", { required: function () { return ($("#Taker_isclear").is(':checked') != _TakerClearStatusOnLoad) }, minlength: 5, messages: { required: "Please provide a reason for changing the clear status", minlength: jQuery.validator.format("At least {0} characters are necessary") } });