Copy link to clipboard
Copied
Hi there
I have a drop down field with 4 options (A, B, C, D). I have a another set of 3 checkboxes with different export values (X, Y and Z).
If options A, B and C are selected, I want the Checkbox with export value Z to be read only and change color to gray.
Is this possible?
Thanks in advance.
MG
Hi ls
Sorry I should have made myself clearer at the start. I don't usually use Export Value in check boxes unless I want it to work like a radio button. Yes, Nesa's code is perfect if I had different field names.
So how should I tweak the script?
Thanks
MM
Hi MM, I must admit if the checkboxes has same name I'm not sure how to adapt code to that(I'm, sure it's simple) but it's beyond my current level 😉 so if ls_rbls can help you he is more then welcome. In the meantime if you want to use my code above and you want checkboxes to act as radio buttons I have workaround for you, name your checkboxes different (example: X,Y,Z) and use this code as mouse up event of each checkbox just change their names if you want, for checkbox "X" use:
if(event.target
...Copy link to clipboard
Copied
Use this code as "Custom Calculation Script" of your dropdown field.
var a = event.value;
var x = this.getField("Z");
if(a == "A" || a == "B" || a == "C"){
x.readonly = true
x.fillColor = ["G", 0.7];
}
if(a == "D"){
x.readonly = false
x.fillColor = color.white;
}
Don't forget to rename fields to your field names and change color white if you want any other color.
Copy link to clipboard
Copied
This code will not work.
Copy link to clipboard
Copied
I tried to recreate fields and using Nesa code. If values in dropdown field are A,B,C checkbox with value of Z should be read only and have grey background, If thats what OP wanted code is working fine.
Copy link to clipboard
Copied
This line is incorrect:
if (a == "A" || "B" || "C"){
If it's working correctly it's pure luck.
Copy link to clipboard
Copied
Well it is working as intended (unless OP had something else in mind) I did try it before posting code, I thought, if (a == "A" || "B" || "C"){ means if values are A,B or C?
I'm still learning myself can you please explain so I can learn for next time? thx
Copy link to clipboard
Copied
I'm sorry if I was a bit curt. It's very good that you're learning and also trying to help others!
JavaScript doesn't support this kind of "shorthand" comparisons. It has be written out in full, like this:
(a == "A" || a == "B" || a == "C")
Copy link to clipboard
Copied
Oh, I knew that 🙂 my brain just turns off sometimes, thx for pointing that out il fix post above,
Copy link to clipboard
Copied
But why did code still work?
Copy link to clipboard
Copied
Because the || "B" || "C" part returned true no matter what the value of the "a" variable was.
Copy link to clipboard
Copied
Thank you all for your help.
The entire script did not work for me. Is there any other way? Thanks.
var amendmentType = this.getField("Z");
if ((event.value == "A")||
(event.value == "B")||
(event.value == "C"))
{
amendmentType.readonly = true;
amendmentType.fillColor = ["G",0.7];
}
else
{
amendmentType.readonly = false;
amendmentType.fillColor = ["RGB",0.874,0.874,1];
}
Copy link to clipboard
Copied
What exactly is not working for you? Did you rename your checkbox field to "Z"?
Here is a file I used to try your code, try it and let me know is that what you wanted or you need something else.
Copy link to clipboard
Copied
I apologize, it seems that I was posting my reply around the same time as you.
Copy link to clipboard
Copied
Hi there
Thanks again. I checked your attachment. The reason why it didn't work for me is that I have identical Field Name (Amendment Type) for all the checkboxes (with different Export Values) as I want the end user to only tick one box at the time. Similar to a radio button function but I don't want to use a radio button.
How would you code it in that case.
Thanks
MM
Copy link to clipboard
Copied
I don't want to sound rude but that is a different question and Nesa's code answered your inquiry correctly.
However, when I was testing the srcipt I had the same observation and I tried to go that route.
It didn't work for me.
The code has to be modified slightly differently.
Copy link to clipboard
Copied
Hi ls
Sorry I should have made myself clearer at the start. I don't usually use Export Value in check boxes unless I want it to work like a radio button. Yes, Nesa's code is perfect if I had different field names.
So how should I tweak the script?
Thanks
MM
Copy link to clipboard
Copied
Hi MM, I must admit if the checkboxes has same name I'm not sure how to adapt code to that(I'm, sure it's simple) but it's beyond my current level 😉 so if ls_rbls can help you he is more then welcome. In the meantime if you want to use my code above and you want checkboxes to act as radio buttons I have workaround for you, name your checkboxes different (example: X,Y,Z) and use this code as mouse up event of each checkbox just change their names if you want, for checkbox "X" use:
if(event.target.isBoxChecked(0)){
this.getField("Y").checkThisBox(0,false);
this.getField("Z").checkThisBox(0,false);
}
for checkbox "Y" use:
if(event.target.isBoxChecked(0)){
this.getField("X").checkThisBox(0,false);
this.getField("Z").checkThisBox(0,false);
}
and for checkbox "Z" use :
if(event.target.isBoxChecked(0)){
this.getField("Y").checkThisBox(0,false);
this.getField("X").checkThisBox(0,false);
}
Copy link to clipboard
Copied
Hi Nesa
Thanks for the workaround. Great to know that.
Thank you for your help. Much appreciated.
Cheers
MM
Copy link to clipboard
Copied
Hi Nesa
That alternative solution worked perfectly.
Thanks so much.
Cheers
Copy link to clipboard
Copied
Don't forget to mark Nesa's answer as correct solution.
Copy link to clipboard
Copied
I marked the wrong comment and I can't find a button to undo 😞 let me know if you know.
But I also marked Nesa's solution as correct answer 🙂
Thanks
Copy link to clipboard
Copied
You got it right.
I was getting stuck with this too.
Copy link to clipboard
Copied
Hi Nesa
Thanks again for your help.
MM
Copy link to clipboard
Copied
You need to be more specific and state where are you trying to run the script from.
Also, if you have placed this script as custom calculation script, the field properties changes will commit once you click outside of the dropdown menu after making a selection.
The script is working fine on my end.
Check that field names in your script match the actual fieldname, like for example, if your fieldname is "Z" is actually types as upper case "Z" not "z".
Copy link to clipboard
Copied
+++UPDATE
I just wanted to add to the answer to this question :
Here is what work for me:
var g = event.value;
var f = this.getField("myDropdown");
if ((g =="A") || (g =="B") || (g =="C")) {
f.checkThisBox(2, true);
this.getField(f.name+".2").fillColor = ["G",0.7];
f.readonly = true;
} else {
f.checkThisBox(2, false);
f.readonly = false;
f.fillColor = ["RGB",0.874,0.874,1];
}
Selecting any any item that is not A, B or C allows to continue to check the boxes again.
This part of the script this.getField(f.name+".2"). doesn't work with the readonly attribute though
You will get the last checkbox in color gray, checked automatically upon the A, B, C selections from the dropdown list, but then it makes the enntire parent group of checkboxes read-only. I am not sure if you wanted to have the ability to continue to check other boxes when the third one was made read-only.
I haven't been able to figure that one out yet. But this works as far as one selection at a time just like radio buttons would behave.