Is it possible to trigger the standard field validation error on a specific field in CRM 2013 using javascript?

Something similar to this would be great..

document.getElementById("fieldname").ForceValidation();

or if possible it would be nice to trigger the message itself.

document.getElementById("fieldname").ShowFieldError("Error Message");

Using standard functionality CRM only shows one error at a time, even if there are multiple required fields that are empty (or incorrect). I would like to trigger the red X on all the empty required fields at once so you don't have to click the save button in order to see the next error.

It's this red x im talking about:

redX

If this is a bad idea, please explain why.

I would personally like to see all errors at once instead of getting them one at a time.

有帮助吗?

解决方案

I don't know of any way to do that, but you can create your own script and attach that to some event on the form, then the script will check all the controls on the form and set a notification if a value is not present.

Here is the code I tried with, probably some cases that I don't handle here, but you get the idea.

function alerter() {

    Xrm.Page.ui.controls.forEach(function(control, index) {
        if(control.getControlType() === "standard" || control.getControlType() === "lookup" || control.getControlType() == "optionset") {
            if(control.getAttribute().getRequiredLevel() === "required" && control.getAttribute().getValue() === null) {
                control.setNotification("Some error");
            }
        }
    });

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top