render issue on UI page triggered by onSubmit client script

alexbones
Tera Expert

trying to have an onSubmit client script bring up a UI page with a dialog box that has users add time they worked on the request and then save that time onto the ticket. The issue I am running into is that the dialog box appears then disappears and saves the ticket before users can input anything. this is my first attempt at doing a UI page so any pointers would be great! most of the code is tweaked from the adding comments UI Page on the wiki.

client script:

function onSubmit() {

    //Type appropriate comment here, and begin script below

      var ccTicket = g_form.getValue('short_description');

   

      if (ccTicket.substring(0,4) == 'CCSC' && g_user.hasRole('itil')){

              var time_work_text = g_form.getValue("time_worked");

              var short_text = g_form.getValue("short_description");

              //Initialize and open the dialog

              var dialog = new GlideDialogWindow("add_time_dialog"); //Instantiate the dialog containing the UI Page 'add_comments_dialog'

              dialog.setTitle("Please Update Community Connect Time Worked"); //Set the dialog title

              dialog.setPreference("time_work_text", time_work_text); //Pass the comments into the dialog

              dialog.setPreference("short_text", short_text); //Pass in a short description for use in the dialog

              dialog.render();//Open the dialog

           

      }

}

UI PAGE

HTML:

<g:ui_form>

  <!-- Get the values from dialog preferences -->

  <g:evaluate var="jvar_short_text"

      expression="RP.getWindowProperties().get('short_text')" />

  <g:evaluate var="jvar_comments_text"

      expression="RP.getWindowProperties().get('time_work_text')" />

    <!-- Set up form fields and labels -->

    <table width="100%">

        <tr id="description_row" valign="top">

              <td colspan="2">

                    <!-- Short description value used as a label -->

                    ${jvar_short_text}

              </td>

        </tr>

        <tr>

            <td>

                <!-- Time worked text field   -->

                <g:ui_input_field name="dialog_comments" id="dialog_comments" label="Add Time worked (hh:mm:ss)"

                      value="00:00:00" mandatory="true" />

            </td>

        </tr>

        <tr>

            <td colspan="2">

            </td>

        </tr>

        <tr id="dialog_buttons">

              <td colspan="2" align="right">

                    <!-- Add OK/Cancel buttons. Clicking OK calls the validateComments script -->

                    <g:dialog_buttons_ok_cancel ok="return validateComments()" ok_type="button" cancel_type="button" />

              </td>

        </tr>

  </table>

</g:ui_form>

UI Page Script

 

function validateComments() {

    //This script is called when the user clicks "OK" in the dialog window

    //Make sure there are comments to submit

    var comments = gel("dialog_comments").value;

    comments = trim(comments);

    if (comments == "") {

          //If comments are empty, alert the user and stop submission

          alert("Please enter your time before submitting.");

          return false;

    }

    //If there are comments, close the dialog window and submit them

    GlideDialogWindow.get().destroy(); //Close the dialog window

    g_form.setValue("time_worked", comments); //Set the "Comments" field with comments in the dialog

      g_form.save();

}

2 REPLIES 2

srinivasthelu
Tera Guru

Hi Alex,



You need to have return false in your on submit client script(conditionally).



function onSubmit() {


    //Type appropriate comment here, and begin script below


      var ccTicket = g_form.getValue('short_description');



      if (ccTicket.substring(0,4) == 'CCSC' && g_user.hasRole('itil')){


              var time_work_text = g_form.getValue("time_worked");


              var short_text = g_form.getValue("short_description");


              //Initialize and open the dialog


              var dialog = new GlideDialogWindow("add_time_dialog"); //Instantiate the dialog containing the UI Page 'add_comments_dialog'


              dialog.setTitle("Please Update Community Connect Time Worked"); //Set the dialog title


              dialog.setPreference("time_work_text", time_work_text); //Pass the comments into the dialog


              dialog.setPreference("short_text", short_text); //Pass in a short description for use in the dialog


              dialog.render();//Open the dialog


         


      }



return false;


}



Mark this answer as helpful/correct if it does so


alexbones
Tera Expert

Hi Srinivas,


I have tried that, but now it doesn't continue processing after I click the OK button. It will just stay on the dialog box.