简体   繁体   English

Adobe Acrobat必需的单选按钮Javascript

[英]Adobe Acrobat Required Radio Buttons Javascript

This is an Adobe Acrobat DC question. 这是一个Adobe Acrobat DC问题。 I'm working on the Javascript area and so I am hoping this is the place. 我正在研究Javascript领域,所以我希望这是一个地方。

Currently creating an application form where there are "Yes" or "No" answers (using radio buttons). 当前正在创建一个答案为“是”或“否”的申请表(使用单选按钮)。 I want them to be required to answer but for some reason, when using the required option (outlined below) it still states that the other radio button needs to be checked. 我希望他们被要求回答,但是由于某些原因,当使用必需的选项(下面概述)时,它仍然指出需要检查其他单选按钮。 I checked and they are in the same group. 我检查了一下,他们在同一个小组中。

  1. I'd like to have the form require either Yes or No to be selected but not both. 我想让表格要求选择是或否,但不要两者都选。 I've used the required selection under Properties>General. 我在“属性”>“常规”下使用了必需的选择。 However, it is still requiring both to be checked even though they are in the same group. 但是,即使它们在同一组中,仍然需要同时检查两者。

I've read several js scripts but they don't seem to fit these needs as it seems to be too simple. 我已经阅读了几个js脚本,但是它们似乎并不满足这些需求,因为它似乎太简单了。

  1. Also, on another part of the form, if the applicant marks "Yes" I'd like a text box then be required (to explain why). 另外,在表格的另一部分,如果申请人标记“是”,则需要一个文本框(以解释原因)。 So, first require a "Yes" or "No" if "Yes" then require "Textbox1" 因此,如果“是”,则首先要求“是”或“否”,然后要求“ Textbox1”

If at all possible, if the applicant hasn't selected an option in the required radio button group, have the group display a message "Select at least one option" 如果可能的话,如果申请人没有在必需的单选按钮组中选择任何选项,请让该组显示一条消息“选择至少一个选项”

The closest I could find to #2 is, I believe: 我认为,最接近第二的是:

if (event.target.value == "Three") {

    this.getField("Text Field 1").required = false;

}

For #3 I believe it is similar to: 对于#3,我认为它类似于:

<script> 
  function validateForm() {   
     var x = document.forms["myForm"]["radioGroupName"].value;   
     if (x == "") {   
        document.getElementById("message").innerHTML = "Select atleast one option";    
     }
   }

</script>

Any assistance would be greatly appreciated. 任何帮助将不胜感激。 Thank you. 谢谢。

PS Here are a couple photos that I hope will convey what I am trying to express better than I have above. 附言:这是几张照片,我希望这些照片能够传达出我想比上面更好地表达的内容。 In the next photo you can see they are all in the same group (radio buttons) and they are all required: Adobe Acrobat In Editor Mode 在下一张照片中,您可以看到它们都在同一组(单选按钮)中,并且都是必需的: Adobe Acrobat在编辑器模式下

And this next is when I am trying to fill out the form as a user using reader. 接下来是当我尝试使用阅读器以用户身份填写表格时。 It shows that the other radio buttons are also required even though they are in the same group: Adobe Reader As A User 它显示了其他单选按钮,即使它们在同一组中,也是必需的: Adobe Reader作为用户

I have been offline for some time… anyway… 我已经离线了一段时间...无论如何...

A very first question is whether you did have a look at the Acrobat JavaScript documentation, in particular the section about required property, and the features of radio buttons in general. 第一个问题是您是否确实查看过Acrobat JavaScript文档,特别是有关必需属性的部分以及单选按钮的一般功能。

If so, it would be obvious that the example shown for #3 is NOT Acrobat JavaScript, and would not work at all in your form. 如果是这样,很明显#3所示的示例不是Acrobat JavaScript,并且在您的表单中根本无法使用。 It would also have become very clear that radio buttons are mutually exclusive by design. 单选按钮在设计上是相互排斥的,这也将变得非常清楚。

In order to make a field required, you actually are very close with the code snippet for #2, only that the required property of the referred field would be true (according to your requirement). 为了使字段成为必填字段,您实际上与#2的代码段非常接近,只是所引用字段的必填属性为true(根据您的要求)。 However, that code snipped lacks the "else" path, where the required property would get reset. 但是,该代码片段缺少“ else”路径,在该路径中将重置必需的属性。

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

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