Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to disable past dates in Datepicker (sp-date-picker) in service portal and also need to add placeholder

divyalakshmi
Tera Guru

Hi,

 I am looking for disabling past date selection in sp-date-picker and also i need to have placeholder text for the Datepicker field. Can anyone help me on this?

Regards,

Divya Lakshmi.

2 REPLIES 2

Gurpreet07
Mega Sage

If its form widget you are using then you could write onChange client scripts for date fields. Catalog client scripts for SRs. Try default value in these fields as an alternative to placeholders.

akasharora
Mega Expert

If you want to do it using script, you can do this

 

var today = new Date();
var priorDate = new Date();

var currentDateObj = priorDate.setDate(priorDate.getDate());

//get start date
var startDateStr = g_form.getValue('date_field');
var startDateNum = getDateFromFormat(startDateStr, g_user_date_format);


if (startDateNum < currentDateObj) {
    alert('Invalid date format Or selected date is in the Past. Select a Future date using date picker');
    g_form.setValue('date_field', '');
}

 

Thanks,
Akash

 

Mark answer helpful or correct if it helps your case.