2 Replies Latest reply on May 7, 2013 2:12 PM by MrGawain

    How to limit OK with a check box

    MrGawain

      I am new to JavaScript.  I have search the web.  I have been working on this box for 3 days.  I have slapped various code from example to get it this far but I cant seem to accomplish my needed last step. 

       

      I need the Check box to also limit the OK button.  AKA "Confirm"  Whether I need a second alert or some other step I am unsure but basically if they don't check the box the only option I want available to them is the cancel button.  Please Help.  Also if you see anything that suggest a novice mistake please point it out.

       

       

       

      var meth0d = {

              initialize: function(dialog) {    // Set a default value for radio button field

                  dialog.load({"rd01": true });

       

                  this.hasPick = false;    // Disable radio button field

                  dialog.enable({   

                      "rd01" : this.hasPick,

                      "rd02" : this.hasPick,

                      "rd03" : this.hasPick });

              },

             

              commit:function (dialog) { // called when OK pressed

                      var results = dialog.store();

       

                          if (results["rd01"]) meth0d = "Rolled";

                      else if (results["rd02"]) meth0d = "Points";

                      else if (results["rd03"]) meth0d = "Manual";

               },

       

              ckbx: function (dialog) {  // Process the checkbox, Verify method

                  this.hasPick = !this.hasPick;

                  dialog.enable({

                      "rd01" : this.hasPick,

                      "rd02" : this.hasPick,

                      "rd03" : this.hasPick });

              },

       

              description:

              {

                  name: "Ability Stat Method",

                  elements:

                  [

                      {

                          type: "view",

                          align_children: "align_left",

                          elements:

                          [

                              {

                                  type: "static_text",

                                  name: "This form has three methods of determining Ability Stat Rolls. \n\n Roll = A computer generated random roll in accordance with the PHB. \n Points = A non-random method that provides balance between players.\n Manual = Allows you to type in any number between 3 to 18  \n\n Note: The Roll Method tracks how many times the form has been opened or\n reset each day and how many reroll attempts the player has made.", 

                                  bold: true,

                                  font: "dialog",

                                  char_width: 30,

                                  height: 140

                              },

                              {

                                  type: "check_box",

                                  item_id: "ckbx",

                                  name: "I understand."

                              },

                              {

                                  type: "view",

                                  align_children: "align_row",

                                  elements:

                                  [

                                      {

                                          type: "static_text",

                                          name: "Methods: "

                                      },

                                      {

                                          type: "radio",

                                          item_id: "rd01",

                                          group_id: "rado",

                                          name: "Rolled"

       

                                      },

                                      {

                                          type: "radio",

                                          item_id: "rd02",

                                          group_id: "rado",

                                          name: "Points",

                                      },

                                      {

                                          type: "radio",

                                          item_id: "rd03",

                                          group_id: "rado",

                                          name: "Manual",

                                      }

                                  ]

                              }

                          ]

                      },

                      {

                          type: "gap",    //Add a small vertical gap between

                          height: 10      //..radio fields and buttons

                      },

                      {

                          type: "static_text",

                          name: "Note: Once you click confirm you will have to reset the form to access this menu again.", 

                          bold: false,

                          font: "dialog",

                          char_width: 30,

                          height: 20

                      },

                         {

                          type: "ok_cancel",

                          ok_name: "Confirm",

                          cancel_name: "Cancel",

                      }

                  ]

              }

          };

      var retn = app.execDialog(meth0d);

        • 1. Re: How to limit OK with a check box
          try67 MVP & Adobe Community Professional

          You need to use the validate function of the Dialog object. It returns a boolean (true/false) that specifies whether the dialog needs to be closed or not (the user can still cancel out of the dialog, of course). So in your case it will be something like this:

           

          validate: function (dialog) {

              var results = dialog.store();

              if (!results["ckbx"]) {

                  app.alert("You must tick the \"I Understand\" box.");

                  return false;

              }

              return true;

          },

          • 2. Re: How to limit OK with a check box
            MrGawain Level 1

            Thank you very much.  I have been racking my brain on this one.  I am still having dificulties with this Validate concept.  Again Thanks.