8 Replies Latest reply on Feb 28, 2017 4:07 AM by gauravahuja11

    How to use guideBridge.validate([], <some-expression>) ?

    urs h. Level 1

      I'm using  guideBridge.validate([], <some-expression>)  and I've expected that children of other panels than the one identified with the SOM-expression would not be validated (as described in Doc). But that's not case.

      var result = [];
      guideBridge.validate(result, <some-expression>) ; 

      Result will only contain errors referring to children of the node identified by <som-expression>. But in the DOM all fields of the form, whose validation fails, will be updated (with css class 'failure').

        • 1. Re: How to use guideBridge.validate([], <some-expression>) ?
          mandeepgandhi Adobe Employee

          I am why this should happen. API is supposed to work for the SOM provided. Can you please share the collateral and the script you are trying. Also what release of AEM Forms are you on ? 

          • 2. Re: How to use guideBridge.validate([], <some-expression>) ?
            urs h. Level 1

            I'm working with AEM 6.1 and Hotfix adobe-aemds-native-x86-win32-pkg-2.2.4.zip installed.

             

            The function looks like this:

            function customizedValidate() { ... var errors = []; if(guideBridge.validate(errors, somExpression)) { ... } ...

            The errors array will only contain messages referring to widgets that are children of the widget (or panel) specified by the somExpression.

            But: On widgets that are children of different parents (more specific: siblings of the one specified by the somExpression) the css class 'validation-failure' is still set and  the  div.guideFieldError of the div.guideFieldNode will contain the error message.

            • 3. Re: How to use guideBridge.validate([], <some-expression>) ?
              rishim22446870 Level 2

              Hi,

              On using the validate API, the fields specified in the validate API get the class "validate-failure" only if the field does not pass the validate test. Probably, in your case, there must be a call to validate the entire AF before the actual validate to the field is called. 

              To verify this, you can perform the following steps:

              a) Open the AF in preview mode.

              b) Once done, before doing any changes in AF, execute the below mentioned script.

              c) Say the som expression of the field to validate is "A", then in the browser console, execute this javascript,

              var errors = []; guideBridge.validate(errors, "A");

              d) Only the field "A" in AF should have the validation-failure class and not the other fields.

              Let me know if you have further doubts/queries.

              Thanks

              • 4. Re: How to use guideBridge.validate([], <some-expression>) ?
                urs h. Level 1

                Hi Rishi

                I've retested following your instructions and I haven't found any "validation-failures" markers in other panels than the one specified.

                So, I guess you were right and in the case of the "error" I reported there was another call before my custom validation that validated all panels.

                Thanks,

                Urs

                • 5. Re: How to use guideBridge.validate([], <some-expression>) ?
                  Balu M Level 1

                  Hi Rishi,

                  How can we invoke custom validations on AF fields, I tried to check text field input data is matching email format or not by writing custom method.

                  But if user click on submit button my custom validations not working. How can we invoke our custom validate method and display error messages when user click on submit

                  Can you share any sample code how to call use validate method.

                  My code:

                  window.addEventListener("bridgeInitializeStart", function(evnt) {
                         gb.connect(function (){
                          gb.on('elementValueChanged', function(event, data) {
                              var elementName = data.target.name;
                              var elementValue = data.target.value;
                              var elemenText = data.newText;

                             
                              var elementNameUppercase = elementName.toUpperCase();
                              if(elementNameUppercase == 'EMAIL'){
                                   if(!validateEmail(elementValue)){ // calling email validation method
                                    console.log("Email is not valid");
                                    list = [{som:data.target.somExpression,errorText: "Email is not valide"},
                                            {som:data.target.somExpression,errorText: "Email is not valide2"}];        

                          }
                              } 
                              if(elementNameUppercase == 'NAME') {
                                  console.log('this is name field');
                              }
                          });
                          gb.on('elementButtonClicked', function(event, data) {
                               
                                gb.validate(list, null); // this method calling not working

                          });

                      })
                  });

                  • 6. Re: How to use guideBridge.validate([], <some-expression>) ?
                    prashantas90507822

                    I am very new to form. May be a silly question, but where we are suppose to write this piece of code ? Is it in clientlibs  ?

                    • 7. Re: How to use guideBridge.validate([], <some-expression>) ?
                      gauravahuja11 Level 1

                      Hi,

                      Yes, you can add these scripts as clientlib. If you want to run scripts on an event ( eg - click of a button), you can add them through the script tab of the edit dialog of that component.

                      • 8. Re: How to use guideBridge.validate([], <some-expression>) ?
                        gauravahuja11 Level 1

                        Hi,

                        Yes, you can add these scripts as clientlib. If you want to run scripts on an event ( eg - click of a button), you can add them through the script tab of the edit dialog of that component.