• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Formularfelder als Ebene oder anhand des Namens gesammelt aus- und einblenden

New Here ,
Jun 27, 2024 Jun 27, 2024

Copy link to clipboard

Copied

Hallo zusammen,
ich habe ein Dropdown-Feld, bei dem je nach Auswahl Formularfelder ein- und ausgeblendet werden.

Aktuell habe ich ein Javascript hinterlegt, bei dem bei jedem if() die einzelnen Felder ein- und ausgeblendet werden, wie im folgenden Beispiel:

 

if(this.getField("dropdown").value == 1){

this.getField("feld1").display = display.visible;

this.getField("feld2").display = display.hidden;

}

 

Gibt es evtl. eine Möglichkeit, die Felder zu einer Gruppe oder Ebene zusammenzufassen und dann die ganze Ebene ein- und auszublenden oder vielleicht anhand der Feldnamen, so à la "alle Felder die 'Januar' im Namen haben sollen ein-/ausgeblendet werden?

 

Meine obige Varianten ist ein riesiger "Roman" und ich würde mir gerne eine Menge Schreibarbeit ersparen 😉

Vielen Dank schonmal für eure Hilfe.

TOPICS
Create PDFs , Edit and convert PDFs , JavaScript , Modern Acrobat , PDF , PDF forms

Views

29

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 27, 2024 Jun 27, 2024

Copy link to clipboard

Copied

LATEST

Assuming you don't want to start renaming the fields in the file, you can do it like this:

 

// Collect all "January" fields into an array
var januaryFields = [];
for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (/january/i.test(f.name)) januaryFields.push(f);
}

// Show/Hide the January fields based on the field's value
if (this.getField("dropdown").value == 1){
	for (var i in januaryFields) {
		januaryFields[i].display = display.visible;
	}
} else {
	for (var i in januaryFields) {
		januaryFields[i].display = display.hidden;
	}
}

 

 

The first part of the code can be placed in a doc-level script, as it only needs to run once.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines