Disabling a field in dialog | Community
Skip to main content
Level 6
April 7, 2021
Solved

Disabling a field in dialog

  • April 7, 2021
  • 2 replies
  • 1935 views

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.
Best answer by Anudeep_Garnepudi

@shaheena_sheikh 

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

2 replies

Asutosh_Jena_
Community Advisor
Community Advisor
April 7, 2021

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!

Level 6
April 7, 2021
I updated 'let' to 'var' and it's still the same 😞
Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
April 7, 2021

@shaheena_sheikh 

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

Level 6
April 7, 2021

thanks! fontField.readOnly=true; works