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

Activating fields depending on selection

Engaged ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

I would like all fields in the rows 1 to 20 to be inactive.

When they choose 1 (in Max Occupancy) then row 1 becomes active whilst the other remain inactive.

When they choose 2, then row 1 and 2 become active whilst the remainig stay inactive.

 

And so on...

can this be done?

 

Screenshot 2023-01-18 at 14.53.57.png

 

 

TOPICS
How to , JavaScript

Views

628

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

correct answers 1 Correct answer

Community Expert , Jan 18, 2023 Jan 18, 2023

You can use this code as the custom Validation script of the drop-down field:

 

var baseNames = ["guestName_", "guestAge_", "outboundDate_", "outboundFlight_", "outboundArrival_", "inboundDate_", "inboundFlight_", "inboundArrival_"];
for (var i=1; i<=20; i++) {
	for (var j in baseNames) {
		var f = this.getField(baseNames[j]+i);
		if (i<=Number(event.value)) {
			f.readonly = false;
		} else {
			f.readonly = true;
			f.value = f.defaultValue;
		}
	}
}

Votes

Translate

Translate
Community Expert ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Yes, using a script. What are the names of the fields?

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
Engaged ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

The dropdown box field is called maxOccupancy

 

The fields in the rows are:

guestName_1

guestAge_1

outboundDate_1

outboundFlight_1

outboundArrival_1

inboundDate_1

inboundFlight_1

inboundArrival_1

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
Community Expert ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

You can use this code as the custom Validation script of the drop-down field:

 

var baseNames = ["guestName_", "guestAge_", "outboundDate_", "outboundFlight_", "outboundArrival_", "inboundDate_", "inboundFlight_", "inboundArrival_"];
for (var i=1; i<=20; i++) {
	for (var j in baseNames) {
		var f = this.getField(baseNames[j]+i);
		if (i<=Number(event.value)) {
			f.readonly = false;
		} else {
			f.readonly = true;
			f.value = f.defaultValue;
		}
	}
}

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
Engaged ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Is there a better way to name the fields so the code can be shorter?

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
Community Expert ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

I guess, but then the field names will be less meaningful (for example, if you name them row1_1, row1_2, etc.). The current field names are fine, in my opinion. What's the problem with the length of the code? Seems very compact to me...

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
Engaged ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Thanks. I was just curious.
I'm assuming i have to tick them all as read only in the properties to start with?

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
Engaged ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Thank You all. It worked.

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
Community Expert ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

LATEST

Nope, just change the value and it will happen automatically. The first line will always be enabled, though, since you don't have a "zero" value in your drop-down. If you want you would add that. You can set a default "Select" item with an export value of zero, and all the lines will be disabled when it's selected.

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
Community Expert ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Lets say your naming of fields is

Row1.1  Row1.2  Row1.3  Row1.4...etc

Row2.1  Row2.2  Row2.3  Row2.4...etc

Row3.1  Row3.2  Row3.3  Row3.4...etc

You could use something like this as validation script of a dropdown field:

for(var i=1; i<=3; i++){
for(var j=1; j<=4; j++){
if(i <= event.value)
this.getField("Row"+i+"."+j).readonly = false;
else
this.getField("Row"+i+"."+j).readonly = true;}}

 

Of course you need to adapt  'i' to number of your rows and  'j' to number of fields in a row.

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