Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Disabling a field in dialog

Avatar

Level 6

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Shaheena_Sheikh 

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

View solution in original post

6 Replies

Avatar

Community Advisor

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!

Avatar

Correct answer by
Community Advisor

@Shaheena_Sheikh 

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

Avatar

Community Advisor
No, Readonly is deprectaed. https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui.... you can use javascript to make it readonly i.e. fontField.readOnly =true;


Arun Patidar
Yes, I am using JS to make my field readOnly. Thanks for the info.