简体   繁体   English

如何动态设置Acrobat中字段的“必需”状态?

[英]How do I dynamically set the “required” status of fields in Acrobat?

I have an Acrobat PDF that a colleague would like some form validation added to beyond the simple options that Acrobat gives you without using javascript. 我有一个Acrobat PDF,同事希望在不使用javascript的Acrobat提供的简单选项之外添加一些表单验证。 From what I can tell, Javascript will be required to do this. 据我所知,将需要Javascript来执行此操作。 I think the behavior should be able to be done via the "Add an Action->MouseDown->Run a Javascript" option found in Properties->Actions of the radio button group. 认为应该可以通过单选按钮组的“属性”->“动作”中的“添加动作-> MouseDown->运行Javascript”选项来完成该行为。

Basically I have a group of radio buttons with 3 buttons. 基本上我有一组带有3个按钮的单选按钮。 If buttonA is pressed, I'd like fieldA to be required. 如果按下buttonA,则需要fieldA。 If buttonB is pressed, I'd like fieldB to be required. 如果按下buttonB,则需要fieldB。 The same for buttonC/fieldC. 对于buttonC / fieldC相同。

I know what my pseudo code is going to look like but I'm having trouble translating it into javascript 我知道我的伪代码看起来像什么,但是我无法将其翻译成javascript

onSelectionChanged(selection) {
    fieldA.required = false;
    fieldB.required = false;
    fieldC.required = false;

    if (selection == 'A') { fieldA.required = true; }
    if (selection == 'B') { fieldB.required = true; }
    if (selection == 'C') { fieldC.required = true; }
}

Can anyone point me in the right direction? 谁能指出我正确的方向? Thank you in advance. 先感谢您。

Did some more digging, here was the eventual solution (placed in the "MouseUp->Run a Javascript" of the radio button group: 做了一些进一步的挖掘,这是最终的解决方案(位于单选按钮组的“ MouseUp-> Run a Javascript”中:

var f = this.getField("ServiceType");

var ins = this.getField("InstallationDateTime");
var rem = this.getField("RemovalDateTime");
var ser = this.getField("ServiceRequestDateTime");

console.println(f.value);

ins.required = false;
rem.required = false;
ser.required = false;

if (f.value === "Install") {
    ins.required = true;       
}
if (f.value === "Removal") {
    rem.required = true;       
}
if (f.value === "Service") {
    ser.required = true;       
}

Pretty easy all things considered, finding the following was really nice for debugging: 考虑到所有事情,一切都很简单,找到以下内容对于调试确实很不错:

f = this.getField("myField");

for ( var i in f ) {
    try {
        if ( typeof f[i] != "function" ) {    // Do not list field methods
            console.println( i + ":" + f[i] ) 
        }
    } catch(e) {
    }           // An exception occurs when we get a property that does not apply to this field type.
}    

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

相关问题 在Adobe Acrobat X Pro中,如何使用javascript以acrobat pdf格式预填充文本字段? - In Adobe Acrobat X Pro, how do I use javascript to prefill text fields in an acrobat pdf form? 使用Recurly JS如何设置需要的不同字段 - Using Recurly JS how do I set different fields to be required 在 Acrobat 中,我可以将数组中的字段设为必填,还是快速将许多字段设为必填/不需要? - In Acrobat, can I make fields in an array required, or quickly make many fields required/not required? 如何在 Acrobat 中使用 javascript? - How do I use javascript in Acrobat? 如何通过excel vba设置Acrobat XI打印机设置? - How do I set Acrobat XI printer settings through excel vba? 如何检查html表单中的必填字段是否已填写? - How do I check if the required fields in an html form are filled? 如何在单个页面上检查多个表单上的必填字段? - How do I check required fields on multiple forms on a single page? 如何验证具有必需属性或不为null的字段? - How do I validate fields with the required attribute or not null? 如何动态使Apex文本字段所需的值 - How do I make Apex text field required value dynamically 如何使需要动态创建的单选按钮-AngularJs - How do I make dynamically created radio buttons required - AngularJs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM