how to add checkbox and radio button fields in a form ?

Adil JEBLI
Mega Expert

Hi,
I want to add checkboxes and radio button in my form, do you have any idea how to do that ?
I check in google and the wiki of servicenow but it existe like a variable in catalog item, in my case i want to add them in my own interface.
thank you.

18 REPLIES 18

reginabautista
Kilo Sage

Hi guys, I would like to know how to do this also. Surely there must be an easy way to create a radio button or checkbox to any bespoke application? Are these really only available in Service Catalog? Thanks


It would be very helpful if you place a step by step screen captures in response to questions. I am trying to create a dynamic checkbox so I changed the type to "list" as per your recommendations and here we are!!Capture.JPG


poyntzj
Kilo Sage

I can think of this - not implemented anything like this myself and not sure how useful it could / would be


Can look at creating a UI Macro + UI Formatter and go from there


certainly cannot use any onChange routine



take the ui macro - ui_radio as your basis


(I have not experimented with the onchange or onclick options so they can probably go)



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


      <g:macro id="${jvar_name}_${jvar_value}" name="" value="" text="" checked_value="" onchange="" />


      <j:if test="${jvar_value == jvar_checked_value}">


          <label>


                  <input type="radio" id="a" name="test" title="a" value="a" checked="checked"


                          onchange="${jvar_onchange}"


                          onclick="${jvar_onchange}">


                      A


      </input><br/>


      <input type="radio" id="b" name="test" title="b" value="b"


                          onchange="${jvar_onchange}"


                          onclick="${jvar_onchange}">


                      B


      </input><br/>


      <input type="radio" id="c" name="test" title="c" value="c"


                          onchange="${jvar_onchange}"


                          onclick="${jvar_onchange}">


                      C


      </input><br/>


          </label>


      </j:if>


      <j:if test="${jvar_value != jvar_checked_value}">


          <label>


                  <input type="radio" id="${jvar_id}" name="${jvar_name}" title="${jvar_text}" value="${jvar_value}"


                          onchange="${jvar_onchange}"


                          onclick="${jvar_onchange}">


                      ${jvar_text}


                  </input>


          </label>


      </j:if>


</j:jelly>




create a ui formatter and attach to a form


radio.PNG



An onSubmit Script



this.strA;


this.strB;


this.strC;



function onSubmit() {


    //Type appropriate comment here, and begin script below


  $$('[id=a]').each(function(elmt) {


  this.strA = elmt.checked;


  });




  $$('[id=b]').each(function(elmt) {


  this.strB = elmt.checked;


  });



  $$('[id=c]').each(function(elmt) {


  this.strC = elmt.checked;


  });


  alert(this.strA + ' : ' + this.strB + ' : ' + this.strC);


}



and then on save


radio save.png


Rahul Kumar17
Tera Guru

hi

here true/false type 

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar