I'm attempting to speed up a web page form-filling workflow by using a Javascript bookmarklet to auto-fill certain fields. I've got everything working except for filling a couple date/time fields which are controlled by Flatpickr. Here is my bookmarklet code, mostly created by FormFillerJS.com:
var d=document;
function i(a){
return d.getElementById(a)}
function n(a){
return d.getElementsByName(a)[0]}
function e(a){
t='change';
if(window.navigator.userAgent.match(/Trident|MSIEs/g)!=null){
x=d.createEvent('Events');
x.initEvent(t,1,0);}
else{
x=new Event(t);}
a.dispatchEvent(x);}
function v(a,v){
a.value=v;e(a)}
function c(a){
a.checked=true;e(a)}
v(i("start-date"),"2018-10-17 11:30");
v(i("end-date"),"2018-10-17 13:30");
v(n("campus"),"1");
v(i("payroll_addendum_category"),"4");
v(i("payroll_addendum_rate"),"Faculty Rate");
v(i("payroll_addendum_course"),"319");
v(i("payroll_addendum_requested_by"),"John Doe");
v(i("notes"),"My note");
void(0);
These two lines…
v(i("start-date"),"2018-10-17 11:30");
v(i("end-date"),"2018-10-17 13:30");
…are not filling at all. I'm a total newbie at this, but my impression is that Flatpickr has to be invoked somehow. Is there any way to do this with a JS bookmarklet, or am I stuck manually picking the date/time with the Flatpickr interface?
If it helps, here is the source I'm seeing around these two fields:
<div class="input-label"><input id="start-date" type="hidden" class="required placeholder flatpickr-input" name="start_date" placeholder="Start Date/Time" value="" data-name="my-payroll-create"><input class="required placeholder flatpickr-input flatpickr-mobile" step="any" type="datetime-local" placeholder="Start Date/Time" min="2018-09-18"><input class="required placeholder flatpickr-input form-control input" placeholder="Start Date/Time" type="hidden" readonly="readonly"><div class="placeholder-label">Start Date/Time</div></div></div>
<div><div class="input-label"><input id="end-date" type="hidden" class="required flatpickr-input" name="end_date" placeholder="End Date/Time" value="" data-name="my-payroll-create"><input class="required flatpickr-input flatpickr-mobile placeholder" step="any" type="datetime-local" placeholder="End Date/Time" min="2018-09-18"><input class="required flatpickr-input form-control input" placeholder="End Date/Time" type="hidden" readonly="readonly"><div class="placeholder-label">End Date/Time</div></div></div>
It seems that instead of your lines:
v(i("start-date"),"2018-10-17 11:30");
v(i("end-date"),"2018-10-17 13:30");
you should use something like these:
i("start-date")._flatpickr.setDate("2018-10-17 11:30", true);
i("end-date")._flatpickr.setDate("2018-10-17 13:30", true);
Hope it will be helpful.
(For more details see the documentation on Flatpickr .)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.