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

Script to detect subform dynamically set presence

Avatar

Level 9

I have a subform named "QAN" that is hidden until the user clicks a radio button. If this subform is visible when the user clicks a custom e-mail button, I want to write a script that checks to see if the QAN subform is visible. I used the following with no success:

if (this.resolveNode("QAN").presence = "visible"){

   do the following...

Can this script detect the presence of a subform that is dynamically changed from hidden to visible?

1 Accepted Solution

Avatar

Correct answer by
Level 5

If you want to check something you have to use == instead of =

If(QAN.presence == "visible")

{

     do the follwing..

}else{}

== is an relational operator

= is an assignment of value (this.rawVaue = 3; means, the current object get the value 3)

Helpful?

Kind regards Mandy

View solution in original post

6 Replies

Avatar

Correct answer by
Level 5

If you want to check something you have to use == instead of =

If(QAN.presence == "visible")

{

     do the follwing..

}else{}

== is an relational operator

= is an assignment of value (this.rawVaue = 3; means, the current object get the value 3)

Helpful?

Kind regards Mandy

Avatar

Level 9

The solution is so simple but not if you don't know the answer! Thank you so very much for your help!

-Don

Avatar

Level 5

No problem. You're welcome!!

You understand it now?

Mandy

Avatar

Level 9

I was able to get the scrit to work by using == in place of =.

Do you ever use single = sign? I have seen triple === also. What is this for?

Thanks

Avatar

Level 10

As Mandy mentioned above above "=" is for assigning a value to something and "==" (or "!=", etc.) is for testing a value.

"===" (and "!==", etc.) is for testing an exact value. JavaScript is called a "loosely typed" language which means that you don't have to specify what type of variable you are using. In languages like Java (strongly typed) you have to specify what type of variable your variable is going to be (integer, string, boolean, etc.).

This can lead to problems sometimes in JavaScript if a number gets converted to a string and then you try to do math with it. By using "===" you can test that the variable is actually a number and not a letter or vice versa.

From some reading I've done it sounds like using "===" is a "best practice" for JavaScript. And it might be faster at performing comparisons, but not sure about that one.

Maybe someone who knows more about JavaScript can explain better.

http://www.w3schools.com/js/js_operators.asp

http://www.w3schools.com/js/js_comparisons.asp

Avatar

Level 9

Thanks Jono. I appreciate you explaining this.

-Don