Skip to main content
Level 6
Apr 7, 2021 8:02 AM UTC
Solved

Disabling a field in dialog

I have the below code:

let fontField = $(".cq-dialog").find("#contentColor")[0];
fontField.value="#ffffff";
fontField.disabled=true;

 

the colorfield shows #ffffff and as disabled. But after closing the dialog, I don't see the color of the font as white (#ffffff). If I comment the line of code having disabled, the color starts reflecting. If i comment the third line of code, the value for the colorfield gets stored in the node but if I don't comment the third line then the value doesn't get stored at all. What am I missing?

(N.B this was working fine until yesterday, but today without making a change, it started breaking.)

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
Community Advisor
Apr 7, 2021 8:43 AM UTC

@shaheena_sheikh 

disabled form fields will not be submitted.  You can try making it readonly.

AG

6 replies

Asutosh_Jena_
Community Advisor
Community Advisor
Apr 7, 2021 8:31 AM UTC

Hi @shaheena_sheikh 

 

Can you change "let" to "var" and try again?

 

The main difference between let and var is that scope of a variable defined with let is limited to the block in which it is declared while variable declared with var has the global scope. So we can say that var is rather a keyword which defines a variable globally regardless of block scope.

 

var fontField = $(".cq-dialog").find("#contentColor")[0];
fontField.value="#ffffff";
fontField.disabled=true;

 

Thanks!

Translate
Level 6
Apr 7, 2021 8:39 AM UTC
I updated 'let' to 'var' and it's still the same 😞
Translate
Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
Apr 7, 2021 8:43 AM UTC

@shaheena_sheikh 

disabled form fields will not be submitted.  You can try making it readonly.

Translate
AG
Level 6
Apr 7, 2021 8:55 AM UTC

thanks! fontField.readOnly=true; works

Translate