CA Service Management

 View Only
  • 1.  Make text field required when check box is checked

    Posted Feb 18, 2015 10:41 AM

    I have a requirement to make a text field required when the checkbox before it is checked.  I'm pretty sure it can be done with a JavaScript function, but I'm not 100% sure how to write the function.  Any assistance would be greatly appreciated.

    Thanks,

    Kevin



  • 2.  Re: Make text field required when check box is checked
    Best Answer

    Posted Feb 21, 2015 07:46 AM

    Hi Kevin,

    there is mighty preSaveTrigger() JS function. Try put this code on your form (assuming that your_checkb_field is checkbox and your_field is the field you want to make required).

     

    Good luck,

    Jakub

     

    function preSaveTrigger()

    {

      var frmMain = document.forms["main_form"].elements;

     

      var checkb = frmMain["SET.your_checkb_field"].value;

     

      if (checkb == 1) {

        detailMakeReq("your_field");

      } else {

        detailMakeReq("your_field", true);

      }

     

      return true;

    }



  • 3.  Re: Make text field required when check box is checked

    Posted Feb 23, 2015 10:27 AM

    That is exactly what I did.

    Thanks,



  • 4.  Re: Make text field required when check box is checked

    Posted Feb 23, 2015 10:35 AM

    I don’t know about the javascript, but have you tried using a data partition.  I achieved the same requirement using both a create and update constraint that is constructed like the following:  (checkbox = 0) OR (textfield IS NOT NULL)

     

    Larry  West

    CA Technologies

    Sr Instructor

    Mobile: +1 952 484 2590

    Laurence.West@ca.com

    <mailto:Laurence.West@ca.com>[Description: Outlook Sig Cert Prof 2013 -L][Description: Outlook Sig Cert Adm 2013]



  • 5.  Re: Make text field required when check box is checked

    Posted Feb 23, 2015 10:51 AM

    Thanks Larry, but the JavaScript works better for this situation, as there are around 15 different checkboxes with additional information text boxes that need to be required if the user checks them.



  • 6.  Re: Make text field required when check box is checked

    Posted Feb 05, 2016 12:38 PM

    Hi Jakub,

     

    This function is very useful. Do this works in all detail forms having a Save button?

     

    Thanks!