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

Activating fields depending on selection

Engaged ,
Jan 18, 2023 Jan 18, 2023

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.pngexpand image

 

 

TOPICS
How to , JavaScript
1.0K
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 ,
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;
		}
	}
}

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

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

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

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

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

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

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

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...

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

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

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

Thank You all. It worked.

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

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

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.

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