0

I am trying to update the error message for a CustomValidator that uses a ValidatorCallOut via javascript. Basically its checking to see if a number entered is an increment of a specified number. I have some code that will update the error message the first time it is run, but after that it will no longer update the error message, although through javascript alerts I see the values are actually being updated. Here is the client side javascript validation function I'm using:

    function checkIncrement(sender, args) {
    var incrementValue = parseInt(sender.orderIncrement); // Custom attribute registered with RegisterExpandoAttribute
    var remainder = args.Value % incrementValue;

    if ((remainder) != 0) {

        var remainder, lowRange, highRange;
        lowRange = parseInt(args.Value - remainder);
        highRange = parseInt(lowRange + incrementValue);

        sender.errormessage = "Closest possible values are <b>" + lowRange + "</b> or <b>" + highRange + "</b>"; // Gets updated once, but not after that
        alert("Low Range: " + lowRange); // always updated with current value

        args.IsValid = false;
        return;
    }

    args.IsValid = true;
}

Any idea on how to keep the error message updated every time this is run to validate?

1 Answer 1

3

Try the following:

sender.errormessage = "Your message here";
var cell = sender.ValidatorCalloutBehavior._errorMessageCell;
// cell is going to be null first time.
if (cell != null) {
    cell.innerHTML = "Your message here";
}

The reason why the message sticks once it has been initialized is because Callout is not created initially. Once it has been created, Callout is just hidden and is not recreated on subsequent showing. Thus, message that it was initialized with when it was created will stick and persist. The above code is a hack and there really should be a method along the lines of set_ErrorMessage, but there isn't one.

Sign up to request clarification or add additional context in comments.

1 Comment

this worked perfect thanks Spark. this answer should be marked as solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.