Calendar Field Type and OnDataChange and OnFocusLost trigger

When I use a calendar field type and use onfocuslost as the trigger I note that the trigger goes off when you hit the little square on the right side of the field to display the calendar. Maybe this is correct behavior because I guess you do loose focus in order to view the calendar?

More problematic is an intermittant error where I use the ondatachange trigger with the calendar field type. It works often but I noted that when I used it to trigger the below script it fires twice. It fires the first time when the data changes and a second time when it encounters the loadrecords command after the “else” in the long script at the bottom of this verbose post.

The method works fine if I use a text field instead of the calendar field to display my date. I have worked around it by using a text field to display the date and application.showCalendar() to change the date. Surprisingly the script doesn’t trigger at all when I use application.showCalendar() to change the data. So I just turned off the ondatachange trigger on the form and I overtly trigger my script like this:

date_of_surgery = application.showCalendar()
SynchronizeSurgery_Calendar();

The method that fires twice:

//Delete Any Prior Record
if(surgery_scheduling_to_events.eventsid)
{
//Delete current record

surgery_scheduling_to_events.deleteAllRecords()
forms.event.controller.saveData()
AdjustTImes();
}

if(!date_of_surgery || !doctor_initials_phone || !place_of_surgery || !duration_surgery)
{
return;
}

//Compute the startdatetime

var thedate = date_of_surgery
var thedayofmonth = thedate.getDate()
thedate.setDate(thedayofmonth + 1)
var thefinaldate = utils.dateFormat(thedate,‘MM/dd/yyyy’);
var thebeginningdate = utils.dateFormat(date_of_surgery,‘MM/dd/yyyy’);
//Compute starting and ending times
var emptystring = ‘’
var maxReturedRows = 50;//usefull to limit number of rows
var query = ‘SELECT eventsid’
query += ’ FROM events’
query += " WHERE doctors_initials =‘" + surgery_scheduling_to_doctors_office.doctorsinitials + "’"
query += " AND start_datetime >= ‘" + thebeginningdate + "’"
query += " AND start_datetime < ‘" + thefinaldate + "’"
query += " AND surgery_schedulingid IS NOT NULL"
query += " AND surgery_schedulingid <> ‘" + emptystring + "’"
var foundset = databaseManager.getDataSetByQuery(controller.getServerName(), query,null, maxReturedRows);
var count = foundset.getMaxRowIndex()
//if not other surgeries are scheduled on this date
if(count == 0)
{
var thestartinghour = utils.stringLeft(surgery_scheduling_to_surgery_centers.start_time, utils.stringPosition(surgery_scheduling_to_surgery_centers.start_time, “:”, 1, 1)-1)
thestartinghour = parseInt(thestartinghour)
var thestartingminute = utils.stringMiddle(surgery_scheduling_to_surgery_centers.start_time, utils.stringPosition(surgery_scheduling_to_surgery_centers.start_time, “:”, 1, 1)+1,2)
thestartingminute = parseInt(thestartingminute)
var thestartingdatetime = date_of_surgery
thestartingdatetime.setHours(thestartinghour)
thestartingdatetime.setMinutes(thestartingminute)
}
else
{
forms.event.controller.loadRecords(foundset)
var thestartingdatetime = forms.event.mex_enddatetime
var thestartinghour = thestartingdatetime.getHours()
thestartinghour = thestartinghour + parseInt(utils.stringLeft(surgery_scheduling_to_surgery_centers.turnovertime, utils.stringPosition(surgery_scheduling_to_surgery_centers.turnovertime, “:”, 1, 1)-1))
var thestartingminute = thestartingdatetime.getMinutes()
thestartingminute = thestartingminute + parseInt(utils.stringMiddle(surgery_scheduling_to_surgery_centers.turnovertime, utils.stringPosition(surgery_scheduling_to_surgery_centers.turnovertime, “:”, 1, 1)+1,2))
if(thestartingminute >= 60)
{
thestartingminute = thestartingminute -60
thestartinghour = thestartinghour + 1
}
thestartingdatetime.setHours(thestartinghour)
thestartingdatetime.setMinutes(thestartingminute)
}

Issue fixed (onDataChange will call once in Servoy 2.1 beta 3)

index-html.txt (1.42 KB)