I have two output field below to display drop down values of year and month. But there is no restrictions on which year and month user can select. could you pls guide me how to add an restriction so that user can select any year staring from current year i.e. 2013 and above and accordingly they can choose the month. Suppose if any user selects 2012 then he should get a error msg saying at least select yr 2013 onwards. Then if he selects month January in 2013 then he should get a error msg that select proper month, eg for 2013 he should get only december available while if he selects 2014 and above he shopuld get Jan to Dec any month..like that .. Any suggestions on how to get the result.
1 Answer
I'm not sure if the default date picker allows this. If you are open to using a custom DatePicker such as this one built by a Force.com MVP Bob Buzzard, you could then enforce these validations in your Apex controller along these lines
if (null!=element)
{
if (element.value.length>0)
{
// date is formatted dd/mm/yyyy - pull out the month and year
var month=element.value.substr(3,2);
var year=element.value.substr(6,4);
if (year < '2013')
{
//show error to user
}
if (year == '2013' && month < '12')
{
// show error for month
}
params+=',month='+month;
params+=',year='+year;
}
}