简体   繁体   English

解决所需的Flatpickr输入并用JS小书签填充表单

[英]Work around Flatpickr input required and fill form with JS bookmarklet

I'm attempting to speed up a web page form-filling workflow by using a Javascript bookmarklet to auto-fill certain fields. 我试图通过使用Javascript书签自动填充某些字段来加快网页表单填充工作流程。 I've got everything working except for filling a couple date/time fields which are controlled by Flatpickr. 除了填写由Flatpickr控制的几个日期/时间字段之外,我已经完成了所有工作。 Here is my bookmarklet code, mostly created by FormFillerJS.com: 这是我的小书签代码,主要由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. 我是一个新手,但是我的印象是Flatpickr必须以某种方式调用。 Is there any way to do this with a JS bookmarklet, or am I stuck manually picking the date/time with the Flatpickr interface? 有什么方法可以使用JS小书签来完成此操作,还是我不得不用Flatpickr界面手动选择日期/时间?

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 .) (有关更多详细信息,请参见Flatpickr上的文档。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM