I am trying to set constraints on date fields in an editable table that are independent for each row. Basically I have a from/to date pair and I want to set the constraint as the data is entered into one so that the other can only be set correctly (i.e. to date is after from date).
I tried using hyf.util.setDateConstraint(repeatId+'toDate', 'Minimum', repeatId+'fromDate') using the repeat ID of the row and it seemed to work but then I noticed that the constraint was changed for every row of the table not only the one edited. Is there a way to make this work correctly? I read the thread here: http://www.hyfinity.net/wmforum/showthread.php?tid=129 but that does not seem to address my requirement. I have used onchange events outside of a repeat object to dynamically set constraints with success, but the editable table has me stumped. (I am using WebMaker 6)
I tried using hyf.util.setDateConstraint(repeatId+'toDate', 'Minimum', repeatId+'fromDate') using the repeat ID of the row and it seemed to work but then I noticed that the constraint was changed for every row of the table not only the one edited. Is there a way to make this work correctly? I read the thread here: http://www.hyfinity.net/wmforum/showthread.php?tid=129 but that does not seem to address my requirement. I have used onchange events outside of a repeat object to dynamically set constraints with success, but the editable table has me stumped. (I am using WebMaker 6)
RE: dynamic date constraints in editable table
I+?+?+?m sorry you are having issues with this.
I think using the setDateConstraint function you mention (eg in an onchange event) is the correct approach, but having just done some testing on this it looks like there is an issue.
From my testing it seems like the constraints are actually getting applied correctly as if you validate the form each field in the table does apply the correct minimum value. However the calendar popup does not seem to behave correctly, and for every field it displays based on the last constraint applied to any of them.
Does this match the behaviour you are seeing? If so, you should be able to fix this by adding the override file in the attached zip as a script file for your page. This overrides a couple of functions from the DisplayUtils.js script file in WebMaker 6 to hopefully resolve this issue.
(It is likely that a future WebMaker release will include a fix for this problem, at which point this override file should be removed.)
As an additional point, in case you haven+?+?+?t seen it yet, I thought it would be mentioning that when setting constraints for fields in a repeating table, there is another function you can use (eg on page load) to initialise all the fields in the table. As listed in the docs, this function is called setRepeatDateConstraint, and you could use it like the following, assuming your repeat is called +?+?++EditableTable+?+?+?.
hyf.calendar.setRepeatDateConstraint(+?+?++EditableTable+?+?+?, +?+?++toDate+?+?+?, +?+?++Minimum+?+?+?, +?+?++fromDate+?+?+?, true);
I hope this helps.
Please let me know how you get on, or if you have any further questions.
Regards,
Gerard
RE: dynamic date constraints in editable table
Yes, you described the behavior I was getting with the calendar always showing the last constraint that was set regardless of which field it was set on. The fix you provided solves this problem for the existing rows (and the setRepeatDateConstraint is especially handy for initialization) however the incorrect calendar behavior still persists for the insert row. It starts out with the constraints set to the same values as the last existing row of the table. This row will only have it's constraints set via onchange events although currently when changing the value in the insert row, the form throws a script error at DIsplayUtils.js line 2264. My onchange function would be generating: setDateConstraint('detailTableBlankEntrytoDate', 'Minimum', 'detailTableBlankEntryfromDate') Do I need to do something different for this row?
RE: dynamic date constraints in editable table
I+?+?+?m glad that fix has helped for the existing rows.
I don+?+?+?t think it will be too hard to resolve the remaining issues with the insert row.
The setDateConstraint function can be called in a slightly different way which I think should help fix the script error. Rather than calling it from the onchange event like
hyf.util.setDateConstraint(repeatId+'toDate', 'Minimum', repeatId+'fromDate')
instead use the following approach:
hyf.util.setDateConstraint('toDate', 'Minimum', repeatId+'fromDate', repeatId)
With this option the function does not have to work out how to split the repeatId from the field name for the field being constrained, which I think should resolve the script error.
With this change, I think the only remaining issue is that the +?+?++to+?+?+? calendar for the insert row will be initially constrained the same as the last existing row, until a +?+?++from+?+?+? value is picked for the insert row.
To resolve this, I think the easiest option would be to edit the CalendarOverrides.js file I provided before. In this file, change the variable definitions on lines 68 and 69 to initialise them as null rather than taking values from the options object. These lines should now look like:
var minExc = null;
var maxExc = null;
I+?+?+?m hopeful that with these changes all the calendars will now be working correctly, but please let me know how you get on.
Regards,
Gerard
RE: dynamic date constraints in editable table