How to make fields mandatory in UI page

patSnow
Tera Contributor

Hi  Team,

How to make fields mandatory in UI page. I have tried "required" but still its not showing as required fields with *.

HTML:

<g:ui_form>
<input type="hidden" id="vulId" name="vulId" value="${sysparm_sys_id}"/>

<div class="modal-body">

<div class="row form-section">
<label for="short_desc" class="col-sm-3 section-title-top">${gs.getMessage('Describe the end user impact in "Production environment" from their daily work perspective. For example what functionalities are being affected as part of this service/application being unavailable or degraded?')}</label>
<div class="col-sm-9 section-title-top" >
<textarea id="short_desc" aria-label="${gs.getMessage('Short description')}" class="col-sm-9 form-control" type="text" name="short_desc" ></textarea>
</div>
</div>

<div class="row form-section">
<label for="radio_field_main" id="radio_field_main" name="radio_field_main" class="col-sm-3 section-title-top">${gs.getMessage('Are any workarounds available to the users?')}</label>
<div class="col-sm-9 section-title-top">
<input type="radio" id="radio_field1" style="min-width: 2em" value="Yes" name="radio_field" onclick="checkValue1();"></input><label for="radio_field1">Yes</label>
<input type="radio" id="radio_field2" style="min-width: 2em" value="No" name="radio_field" onclick="checkValue2();"></input><label for="radio_field2">No</label>
</div>
</div>

<div class="row form-section">
<label for="date_field" class="col-sm-3 section-title-top">${gs.getMessage('When did the issue start')}</label>
<div class="col-sm-9 section-title-top">
<g:ui_date_time name="project_start_date" value="${jvar_start_date}"/>
</div>
</div>

<div class="row form-section">
<label for="desc" class="col-sm-3 section-title-top">${gs.getMessage('Which territories are impacted?')}</label>
<span class="col-sm-9 section-title-top">
<textarea id="desc" aria-label="${gs.getMessage('Description')}" class="col-sm-9 form-control" rows="3" type="text" name="desc" ></textarea>
</span>
</div>

<div class="row form-section" >
<label for="users_impacted" class="col-sm-3 section-title-top" >${gs.getMessage('How many users are impacted, both now and potentially?')}</label>
<div class="col-sm-9 section-title-top" >
<textarea id="users_impacted" aria-label="${gs.getMessage('Short description')}" class="col-sm-9 form-control" type="text" name="users_impacted">No. of users impacted now -
No. of potential users impacted -</textarea>
</div>
</div>

</div>
<footer class="modal-footer">
<!-- <g:dialog_buttons_ok_cancel ok="return onSubmit();" cancel="return onCancel();"/> -->
<button class="btn-default btn" style="min-width: 5em" onclick="return onCancel();" name="cancel" id="cancel">${gs.getMessage('Cancel')}</button>
<button class="btn-primary btn" name="submit" onclick="onSubmit();" id="submit" style="min-width: 5em">${gs.getMessage('Submit')}</button>
</footer>
</g:ui_form>

 

Client script: 

function onCancel() {
GlideDialogWindow.get().destroy();
return false;
}

function onSubmit() {
var short_desc = gel("short_desc").value;
var date = gel("project_start_date").value;

------------- ----- -----

GlideDialogWindow.get().destroy();

}

 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the only way is to use Client Script of the UI Page and check the HTML id is having value or not

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

I tried by fetching details in client script and using if loop i tried to compare as well. But every time 

system tries to leave the page. any idea how we can avoid below popup ?

find_real_file.png

Hi,

please share updated script HTML, Client Script and Processing script

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@patSnow 

refer these link if that helps

creating a mandatory field in ui page?

Make UI Page Text area mandatory

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader