Hi all,
if you want to change client side the mandatory status of a field, you can use these two functions:
//eg. addValidator("customerid", "Customer")
function addValidator(fieldName, fieldLabel) {
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
$("#" + fieldName + "_label").parent().addClass("required");
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "RequiredFieldValidator" + fieldName;
newValidator.controltovalidate = "casetypecode";
newValidator.errormessage = "<a href='#" + fieldName + "_label'>" + fieldLabel + " is a mandatory field.</a>";
newValidator.validationGroup = "";
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
var value = $("#" + fieldName).val();
if (value == null || value == "") {
return false;
} else {
return true;
}
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);
// Wire-up the click event handler of the validation summary link
$("a[href='#" + fieldName + "_label']").on("click", function () { scrollToAndFocus(fieldName + '_label', fieldName); });
}
//eg. removeValidator("customerid")
function removeValidator(fieldName) {
$.each(Page_Validators, function (index, validator) {
if (validator.id == "RequiredFieldValidator" + fieldName) {
Page_Validators.splice(index, 1);
}
});
$("#" + fieldName + "_label").parent().removeClass("required");
}
This code works only if the field was not previously mandatory on the CRM. I suggest you to use this code in order to manage mandatory fields directly client side.
Hope this helps.
*This post is locked for comments
I have the same question (0)