Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Validation in custom stamps  (Read 6337 times)

steph

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 8
Validation in custom stamps
« on: August 21, 2017, 04:23:18 PM »

hi, I am working on a custom stamp that has a dialog popup before stamp is applied. The dialog has 2 sections containing groups of radio buttons. The user must select one of the radio buttons in each group. When I validate however it only validates the first group. If I put the validation code of the second group first, then it only validates the second group. So basically it validates a group, then returns either true or false, and does not proceed to the second validation.

I tried only returning false after the second group - this almost works - it does validate both if both are false (I get 2 alert boxes with the correct messages), but if the first group is set to true, it returns true and exist without running the second part.

the closest explanation I can find is that I need to add a 'name' attribute to my input fields - however that is for html... my radio buttons do have a name though. Any ideas? Here is my validation code.

sd.validate = function(dialog)
   {
                var res = dialog.store();
      for (var i = 0; i < this.builder.radioButtons1.length; ++i)
      {
         var c = this.builder.radioButtons1;
         var id = "rad1" + i;
         if (res[id] == true)
         return true;
      }
                app.alert(this.builder.radioErrorMsg1);
      return false;

                var res = dialog.store();
                for (var i = 0; i < this.builder.radioButtons2.length; ++i)
      {
         var c = this.builder.radioButtons2;
         var id = "rad2" + i;
         if (res[id] == true)
            return true;
      }
                app.alert(this.builder.radioErrorMsg2);
      return false;
   };

----------------and here is the global script defining the groups

 radioGroup1 : "Constructed",
    radioButtons1 :
    [
      { value:"WithRedlines", description:"As-constructed, with redlines"},
      { value:"NoChanges", description:"As-constructed, no changes" },
      { value:"OutOfScope", description:"As-constructed, with redlines, out of scope" }
    ],

    radioErrorMsg1 : "Please select an as-constructed value.",

    radioGroup2 : "Redlines",
    radioButtons2 :
    [
      { value:"Contractor", description:"Contractor Redlines"},
      { value:"Inspector", description:"Inspector Redlines" },
      { value:"Comissioning", description:"Comissioning Redlines"},
      { value:"Other", description:"Other Redlines" }
    ],
    radioErrorMsg2 : "Please select a Redline type."

----------------------and here is the dialog builder that assigns a name to the radio buttons
typeElements =
         {
            type: "radio",
            name: c.description,
            item_id: "rad2" + i,
            group_id: "grp2"            
         };

----------any thoughts?

Logged

steph

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 8
Re: Validation in custom stamps
« Reply #1 on: August 22, 2017, 10:26:43 AM »

I figured it out... nested 'if' statements. Probably not the best solution since it would get really ugly if you start getting more things to validate, but for 2 elements it works ok. Here is the code if anybody is facing the same issue

sd.validate = function(dialog)
   {     
                var res = dialog.store();
      for (var i = 0; i < this.builder.radioButtons1.length; ++i)
      {
         var c = this.builder.radioButtons1;
         var id = "rad1" + i;
         if (res[id] == true)
                        {
                           for (var i = 0; i < this.builder.radioButtons2.length; ++i)
                 {
                  var c = this.builder.radioButtons2;
                  var id = "rad2" + i;
                  if (res[id] == true)
                                  {
                                     return true;
                                  }
                 }
                           app.alert(this.builder.radioErrorMsg2);
                 return false;
                        }
       }
                 app.alert(this.builder.radioErrorMsg1);
       return false;
   };
Logged

Steve

  • Administrator
  • Sr. Member
  • *****
  • Karma: +7/-0
  • Posts: 367
    • RevuHelp
Re: Validation in custom stamps
« Reply #2 on: August 22, 2017, 10:35:52 AM »

Great.  The scripting is beyond where I am at with Revu, but my only suggestion, based on looking at the code, would have been trying some type of if...then...else combination (though I have no idea how to implement that in the code), so I guess I understood it better than I thought!  LOL

Good luck!
Logged
Steve Jones
RevuHelp Forum Admin
steve@revuhelp.com
www.revuhelp.com
www.facebook.com/RevuHelp

Thanaburn

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 2
    • สโบเบ็ต
Re: Validation in custom stamps
« Reply #3 on: October 17, 2017, 10:32:51 PM »

It is a very good thing And the explanation is really thorough.
Logged