[英]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.