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

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

New Here ,
Jun 27, 2024 Jun 27, 2024

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
414
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 27, 2024 Jun 27, 2024

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.

View solution in original post

Translate
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

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.

Translate
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
New Here ,
Sep 30, 2024 Sep 30, 2024
LATEST

Works perfectly, many thanks for your help 🙂

Translate
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