I'm trying to restrict the date control on a field in an editable table. I tried using this:
hyf.calendar.setDateConstraint('my_date_field', 'Maximum', 'Today');
For my_date_field I've set the ID of the field as it shows up in Webmaker. When I do this I get this error:
Error: document.getElementById(dateField) is null
If I set my_date_field to the actual ID of a field in the editable table, for example TasksBlankEntrymy_date_field, then I get a different error:
Error: calendarConfig is undefined
What am I doing wrong?
hyf.calendar.setDateConstraint('my_date_field', 'Maximum', 'Today');
For my_date_field I've set the ID of the field as it shows up in Webmaker. When I do this I get this error:
Error: document.getElementById(dateField) is null
If I set my_date_field to the actual ID of a field in the editable table, for example TasksBlankEntrymy_date_field, then I get a different error:
Error: calendarConfig is undefined
What am I doing wrong?
RE: date constraints on a field in editable table
Unfortunately, the version of the setDateConstraint function included in WebMaker 3.1.2 dos not support date fields within a repeat structure (eg a table), which is why you are seeing these errors.
To resolve this, please add the script file in the attached zip as an additional script file for your page. (This can be done on the Application Map screen.)
Next change your script call to be:
hyf.calendar.setRepeatDateConstraint('repeat_name', 'field_name', 'Maximum', 'Today');
Where repeat_name is the name of the repeat control that contains the date field. For a default editable table this will be EditableTable.
Finally, to ensure the fields are correctly initialised in the editable table, you should put this script call in an onbeforeload page event, rather than an onload one.
Hopefully this should sort out this problem for you.
Please let me know if you have any further questions.
RE: date constraints on a field in editable table
Is there a way to control the location of the calendar popup? By default it happens below and to the left of the control. I would like to have it pop up above the control for example.
Also can I ask why you didn't simply use/extend the dojo calendar control?
RE: date constraints on a field in editable table
dojo.connect(hyf.calendar, 'getCalendar', function (fieldId){ var cal = hyf.calendar.config[fieldId].calendar; cal.offsetY = -150; cal.offsetX = -150; });
With regards to not using the dojo calendar, I think this functionality was originally implemented before the dojo toolkit existed, which is why it is not used. You should however be able to switch to using a different calendar control if you want. See How do I change the calendar/date picker control used on the created pages? for more details.
I hope this helps.
RE: date constraints on a field in editable table
When I try to specify a field id instead of 'Today' as a constraint, I get this error:
Error: start is null
Source File: /js/CalendarPopup.js
Line: 344
For example I do this:
hyf.calendar.setRepeatDateConstraint('myRepeatId', 'myFieldId', 'Maximum', 'anotherFieldId')
Where anotherfielId is a date field.
RE: date constraints on a field in editable table
I think you might get that error if the anotherFieldId value is blank. So it might be worth wrapping your script call, eg
if (document.getElementById('anotherFieldId').value != '') hyf.calendar.setRepeatDateConstraint('myRepeatId', 'myFieldId', 'Maximum', 'anotherFieldId')
I hope this helps.
RE: date constraints on a field in editable table
RE: date constraints on a field in editable table
Can you check that the anotherFieldId field has the Data Type set to 'date' (under Data Constraints on the Field Details tab in FormMaker), and that its Data Date Format is the same as the that for the field you are trying to restrict?
RE: date constraints on a field in editable table
RE: date constraints on a field in editable table
I'm hoping that this may resolve this timing conflict, but please let me know how you get on.
RE: date constraints on a field in editable table
RE: date constraints on a field in editable table
You can then manually add one day to the date specified by the field before using the value to restrict.
eg Use a fragment like the following in your onload event rather than just a simple call to setRepeatDateConstraint:
var sourceField = document.getElementById('anotherFieldId'); if (sourceField.value != '') { var time = getDateFromFormat(sourceField.value, sourceField.getAttribute('_display_date_format')) if (time != 0) { time += 86400000; //milliseconds in a day var dateString = formatDate(new Date(time), sourceField.getAttribute('_data_date_format')); hyf.calendar.setRepeatDateConstraint('myRepeatId', 'myFieldId', 'Maximum', dateString); } }