Skip to main content
Participant
December 21, 2018
質問

Removing red required field from radio buttons after one of them is selected?

  • December 21, 2018
  • 返信数 1.
  • 3748 ビュー

I'm preparing a form and I was able to find the Javascript to remove the red required border from text fields after they've been filled in, but I can't figure out how to remove the red required border from my radio buttons after one of them has been selected. It looks confusing and as if they still have to complete something if the red border stays around the buttons after they've made a selection. Is there a code or function that will remove the red border?

Here's an example of where I need to require that a button is selected, but once it's selected it confusingly is still red:

返信数 1

Thom Parker
Community Expert
Community Expert
December 21, 2018

The fields only acquire the red border after form submission fails because a required field is not filled. The the border is removed after a successful submission. So no scripts are required at all, unless there is something else going on.

Is a script used to apply the red border? And what script did you use to "remove the red required border"?

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
December 21, 2018

The only thing I clicked is the "Set as required field" button when you right-click and I'm confused why the three unchecked buttons would still have the red/pink border if one of the 4 buttons from the group is checked.

For the text fields that are required and not the radio buttons, I found:

if(event.value != ""){

    event.target.required = false;

}

else {

    event.target.required = true;

}

and it successfully gets rid of that red/pink border when I type into the fields.

try67
Community Expert
Community Expert
March 14, 2025

This is what I have:

var requiredFields = ["Group3"];
var allFilled = true;

for (var i = 0; i < requiredFields.length; i++) {
var field = this.getField(requiredFields[i]);
if (field.valueAsString!=field.defaultValue) {
allFilled = false;
break;
}
}

if (allFilled) {
this.getField("Group3").display = display.visible; // Show the signature field
} else {
app.alert("Please fill in all required fields before signing.");
}

 

When I click the button now, the app alert pops up regardless of if a radio button is selected or not


Sorry, my bad. It should be:

if (field.valueAsString==field.defaultValue) {

 

Also, this part of the code doesn't make sense:

 

if (allFilled) {
this.getField("Group3").display = display.visible; // Show the signature field

}

 

Group3 is the radio-button group, not a signature field. So either change it or remove it.