This topic is locked
[SOLVED]

Restricting date control by day of week results in unwanted default setting

9/20/2021 3:16:35 PM
ASPRunner.NET General questions
Pete K author

I have a Date field with no default value specified, with a simple edit box and a calendar control, with allowed days set to weekdays:

img alt

The resulting app however sets the default date to today or to the next valid date upon page load:

img alt

If I remove the weekday restirction, the app behaves as expected, with the date field blank on intial page load. I tried turning this off in the GUI and instead setting the restricted days using the date control API, but that resulted in the same behavior. I don't think this is the intended behavior -- it least, it shouldn't be.

—Pete

Pete K author 9/21/2021

I solved it by setting the value of the control to empty in the JavaScript Onload event, after the other code:

// Don't allow past dates or weekends for ReqDate

var ctrl = Runner.getControl(pageid, 'ReqDate');
var moment_date = moment().add(-1, 'days');
ctrl.setAllowedInterval( moment_date, null, 'You selected a day in the past. Please correct.' );
ctrl.toggleWeekDay( [0,6], false, 'You must select a weekday');
ctrl.setValue('');

I still don't think this should be happening though.