Custom field plugin, struggling with initializing a field that needs to first exist on the DOM.
Custom field plugin, struggling with initializing a field that needs to first exist on the DOM.
This might not be 100% a DataTables issue, but im hoping the DT API has something here that can help me.
I am trying to wrap this into a DTE Field Plugin: https://github.com/koss-lebedev/bootstrap-duration-picker
The problem is, that plugin tries to do something like this https://github.com/koss-lebedev/bootstrap-duration-picker/blob/master/src/bootstrap-duration-picker.js#L39
I found that because my input does not actually exist on the DOM it is hidden and then the new input is never added or created.
My plugin create basically looks like this:
conf._input = $('<input>');
conf._input.durationPicker();
return conf._input;
And my input ends up looking like this:
<input style="display: none;" />
How can I first attach the input to the DOM? setTimeout? Some type of callback?
Thanks
Answers
there is some kind of callback when new / edit button clicked. Also you can always init the duration picker after the new / edit button clicked.
Would:
do?
Allan
@allan Does not seem to do the trick. The setValue fails (
onf._input.data('durationPicker').setValue(0)
) becauseDuration.Plugin.js?v=MmRzVbG7EGg2X215091RfnCrhV-uE0pE7usyION9Lrk:41 Uncaught TypeError: Cannot read property 'setValue' of undefined
Its acting like it was never initialized as a durationPicker. Im going to try the on init event for editor
More or less what I went with
And that is doing the job for you now? Super - thanks for sharing it!
Allan
@allan Yes that works for me, why do you sound surprised? That makes me nervous like I did something wrong lol
Also, for anyone else using .NET Core, I use moment and moment-duration-formatter plugin to do a quick format to a C# ViewModel TimeSpan property.
Haha - it was just one of those ones where I wasn't 100% sure what the cause was .
Allan