Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Timing Problem when Sending an Ajax Request inside a custom validator

    I wanted to create a custom Validator, that sends an ajax-request. After some validation on the server, the right case should be returned. The problem is, that the ajax-request needs a moment to answer, so that the return is excecuted before the variable could be set. Is there any way, I can avoid or solve this problem.

    Code:
        
    isc.Validator.addValidator(
        "serversideValidator", 
        function (item,validator,value) {
            var validator_return = null;
            isc.RPCManager.sendRequest({
                httpMethod: "GET",
                useSimpleHttp: true,
                evalResult: false,
                actionURL:"/ajax/read/2/validator/" + item.name + "/" + value ,
                callback:
                    function (rpcResponse, data, rpcRequest) {
                        validator_return = false;
                        if (data == 'true'){
                            validator_return = true;
                        }
                    },
            });
            if (validator_return!=null){
                return validator_return;
            }
        }
    );

    #2
    Use a type:serverCustom Validator. Examples are in the Feature Explorer under Server Examples -> Validation.

    Comment


      #3
      I forgot to say, that i am only using the Rest-Api of Smartclient with JavaScript and JSON and neither Java nor XML.

      Comment


        #4
        In that situation, we do not declare a validator on the client side. When a REST add or update is sent to the server, if the record is not valid, we send back a JSON response with status -4 (STATUS_VALIDATION_ERROR), and the error messages. You'll find a JSON example with error messages in the RestDatasource documentation.

        Comment


          #5
          Thank you for your help so far.
          Now I just need to know, how I can arrange it, that a certain field is recognized as wrong and gets the flag beneath it. How can I do that?

          Comment

          Working...
          X