How to restrict users to only pick from calendar icon

samadam
Kilo Sage

I have a date field which I want to restrict users from manually entering the values instead only use the calendar icon to pick. Is this possible?

1 ACCEPTED SOLUTION

Another approach is to use a UI Policy with Run scripts and On load checked, and Isolate script unchecked.  Use a script like this in the Execute if true box

function onCondition() {
	var $ = this.jQuery;
	$('input[id="table_name.field.name"]').attr('readonly', true);
}

 

View solution in original post

8 REPLIES 8

Brad Bowman
Kilo Patron
Kilo Patron

You could use a script like this with your field name:

function onLoad() {
    // Sets the field's background to a gray, making is appear read-only.
    g_form.getControl('field_name').className='disabled';
    // Sets the field read-only
    g_form.getControl('field_name').readOnly=true;
}

Joe Wong
Tera Guru

Brad, I was about to suggest the same solution, but I noted that the g_form.getControl does not work in Service Portal.  I was able to get your script to work on native UI, but not within Service Portal.

samadam
Kilo Sage

I tried it but did not work

Is this a field on a form, or a variable on a Catalog Item?  Are you using the native UI, or Service Portal?