This is a public Forum  publicRSS

Topic

    Bruno Aun
    Conditional Required Fields
    Topic posted August 2, 2017 by Bruno AunExplorer 
    147 Views, 5 Comments
    Title:
    Conditional Required Fields
    Content:

    Hi There,

    Here's the requirement I have in PSEUDO CODE

    IF
         Radiobutton is marked "YES"
    THEN
         make Textbox required
    ELSE (marked as "NO")
         leave Textbox not required

    If this was plain Javascript or JQuery I could easily write it.
    I've searched for similar code online but couldn't find anything useful.

    So if anyone could provide any insight on how to go about this, it would be greatly appreciated

    Thanks in advance,
    Bruno

    Answer

     

    • Pramod Vasudeva Murthy

      I would write a simple widget from the scratch and enable logic.js and do the following steps:

      • Since this is a radio button; subscribe for checked event
      • After that, you can either fire an even to make the textbox widget(custom of-course) to have required attribute
      • OR remove rn_Required class from that widget(It used to work in previous versions, not sure if it will work for existing)

      Here is a sample code:

      Radio button check:

      if(document.getElementsByName('<radio_button_custom_field_name>')[0].checked)
      {
      document.getElementsByName('<text_field>')[0].removeClass = "rn_Required";
      }
      else
      {
      document.getElementsByName('<text_field>')[0].addClass = "rn_Required";
      }

      ~VIP

    • Bruno Aun

      Hi Pramod V,

      Thanks a lot for your input. I will give it a shot.

      Cheers,
      Bruno

    • Lage Antony

      Hi Bruno,

      I am sure that Pramod code works. I am also posting how this can be achieved in YUI

      if(args[0]==true)

         {

           this.data.attrs.required = true;

           //this.Y.one('#Div_FileAttachment').hide();

          

         }

         else

         {

          this.data.attrs.required = false;

          //this.Y.one('#Div_FileAttachment').show();

       

         }

      Thanks,

      Lage Antony

    • Danette Beal

      Hi Bruno,

      Make sure to come back and let us know what you ended up doing.

      Regards,

      Danette, Community Manager

    • Bruno Aun

      Sorry for the lack of feedback

      I had to prioritize other project here, so I'll get back to this next week and I'll let you know what happens.

      I am more inclined to use plain JS then YUI, because I have zero experience with the latter

      Thanks anyways