Editor Datetimepicker with dependencies
Editor Datetimepicker with dependencies
I'm using the Bootstrap 2 Datetime picker plug-in for some of my editor fields:
{
label: "Start Date:",
labelInfo: "(UTC Time)",
name: "start",
type: "datetime",
dateFormat: "mm/dd/yy 00:00:00"
}, {
label: "End Date:",
labelInfo: "(UTC Time)",
name: "end",
type: "datetime",
dateFormat: "mm/dd/yy 00:00:00"
}
and I have dependencies on these fields. However, I cannot get the dependencies to work. I have tried adding events to the options list as the 3rd parameter of dependent() but it does not respond. Is there a specific event I should be specifying for the datetime field dependency to be triggered?
Here is a sample of the dependency:
editorInner.dependent('start', function () {
var start = editorInner.field('start');
var end = editorInner.field('end');
var dur = moment(end.val(), "MM/DD/YYYY").diff(moment(start.val(), "MM/DD/YYYY"), 'days');
var d = dur +" d 0 h";
editorInner.field('duration').set(d);
}, {event: "change dp.change"});
Thank you in advance for the help!
This question has an accepted answers - jump to answer
Answers
It would appear that the date time picker, somewhat unusually, triggers the event on the container
div
rather than theinput
element. For this reason the event gets "missed" (dependent()
is listening for it on a different element).I've tried adding code to make the change event trigger from the input element, but the library just swallows that. However, making it trigger a custom named event works. Add the following to the
init
function for the plug-in:And listen for that event using the
event
option in thedependent()
options.I think this is a bug in the 3rd party library, so i'm not going to code around it in Editor.
Allan
Thanks so much! That worked perfectly.