<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How to make textarea and select box mandatory in UI page on click of a button in the same UI page? in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592466#M164245</link>
    <description>&lt;P&gt;you mean to say if its empty thru document.getElementById()? can u explain it in detail, or help me with code snippet&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 23 Nov 2020 10:07:48 GMT</pubDate>
    <dc:creator>Shruthi2</dc:creator>
    <dc:date>2020-11-23T10:07:48Z</dc:date>
    <item>
      <title>How to make textarea and select box mandatory in UI page on click of a button in the same UI page?</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592463#M164242</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;How to make textarea and select box mandatory in UI page on click of a button in the same UI page?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;can anyone help me with this ?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thanks&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 09:34:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592463#M164242</guid>
      <dc:creator>Shruthi2</dc:creator>
      <dc:date>2020-11-23T09:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to make textarea and select box mandatory in UI page on click of a button in the same UI page?</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592464#M164243</link>
      <description>&lt;P&gt;Hi Shruthi&lt;/P&gt;
&lt;P&gt;Add the required attribute&lt;/P&gt;
&lt;P&gt;example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;lt;input type="text" id="username" name="username" &lt;STRONG&gt;required&lt;/STRONG&gt;&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this doesn't work you can use the client script like below&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;
if(gel('ID').value==''){//input the id of the field


alert("fieldname is mandatory is mandatory.");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;There is another way also to do it&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here is the full code&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;HTML&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;&amp;lt;label for="input1" id="inputLabel" &amp;gt;Name&amp;lt;/label&amp;gt;
  &amp;lt;input type="text" ng-model="name" onchange="checkMandatory()" id="demo"  /&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Client script&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;document.getElementById('inputLabel').setAttribute("class", "required");

function checkMandatory(){
if(document.getElementById('demo')!="")
document.getElementById('inputLabel').setAttribute("class", "notrequired");

}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;CSS&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="language-css"&gt;&lt;CODE&gt;label.required::before {
  content: '*';
  margin-right: 4px;
  color: red;
}
label.notrequired::before {
  content: '*';
  margin-right: 4px;
  color: grey;
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reference Links&lt;/P&gt;
&lt;P&gt;https://community.servicenow.com/community?id=community_question&amp;amp;sys_id=c217a403db31a3406c1c02d5ca961936&lt;/P&gt;
&lt;P&gt;https://community.servicenow.com/community?id=community_question&amp;amp;sys_id=83764325db1cdbc01dcaf3231f961993&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Pranav&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 09:44:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592464#M164243</guid>
      <dc:creator>Pranav Bhagat</dc:creator>
      <dc:date>2020-11-23T09:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to make textarea and select box mandatory in UI page on click of a button in the same UI page?</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592465#M164244</link>
      <description>&lt;P&gt;Hi Shruthi,&lt;/P&gt;
&lt;P&gt;You will have to check it via script in the client script when user clicks on the button&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 09:49:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592465#M164244</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-11-23T09:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to make textarea and select box mandatory in UI page on click of a button in the same UI page?</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592466#M164245</link>
      <description>&lt;P&gt;you mean to say if its empty thru document.getElementById()? can u explain it in detail, or help me with code snippet&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 10:07:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592466#M164245</guid>
      <dc:creator>Shruthi2</dc:creator>
      <dc:date>2020-11-23T10:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to make textarea and select box mandatory in UI page on click of a button in the same UI page?</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592467#M164246</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;yes you will have to check if the html id is having any value or not&lt;/P&gt;
&lt;P&gt;Sample below&lt;/P&gt;
&lt;P&gt;HTML:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;
&amp;lt;j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"&amp;gt;

	&amp;lt;g:ui_form&amp;gt;
		&amp;lt;table border="0" width="100%"&amp;gt;
			&amp;lt;tr&amp;gt;
				&amp;lt;td&amp;gt;
					&amp;lt;input type="text" name="reason" id="reason"&amp;gt;&amp;lt;/input&amp;gt;
				&amp;lt;/td&amp;gt;
				&amp;lt;td&amp;gt;
					&amp;lt;textarea id="my_text_area" name="comments"&amp;gt;&amp;lt;/textarea&amp;gt;
				&amp;lt;/td&amp;gt;
				&amp;lt;td&amp;gt;
					&amp;lt;select name="cars" id="cars"&amp;gt;
						&amp;lt;option value=""&amp;gt;None&amp;lt;/option&amp;gt;
						&amp;lt;option value="toyota"&amp;gt;Toyota&amp;lt;/option&amp;gt;
						&amp;lt;option value="mercedes"&amp;gt;Mercedes&amp;lt;/option&amp;gt;
						&amp;lt;option value="audi"&amp;gt;Audi&amp;lt;/option&amp;gt;
					&amp;lt;/select&amp;gt;
				&amp;lt;/td&amp;gt;
			&amp;lt;/tr&amp;gt;
			&amp;lt;tr&amp;gt;
				&amp;lt;td&amp;gt;
					&amp;lt;g:dialog_buttons_ok_cancel cancel="return onCancel();" ok="return onSubmit();"/&amp;gt;
				&amp;lt;/td&amp;gt;
			&amp;lt;/tr&amp;gt;
		&amp;lt;/table&amp;gt;
	&amp;lt;/g:ui_form&amp;gt;

&amp;lt;/j:jelly&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Client Script:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onCancel() {
	GlideDialogWindow.get().destroy();
	return false;
}

function onSubmit() {
	var textAreaValue = gel('my_text_area').value;
	if(textAreaValue == ''){
		alert('Please provide text area');
		return false;
	}
	if (document.getElementById('cars').value == '') {
		alert('Please select drop down');
		return false;
	}
	return true;
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 10:21:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-make-textarea-and-select-box-mandatory-in-ui-page-on/m-p/592467#M164246</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-11-23T10:21:11Z</dc:date>
    </item>
  </channel>
</rss>

