I'm having this problem assigning value 'FALSE' to the <div> attribute.
I need to implement the following HTML
<div d-automode="${obj.message}"> <p>Content goes here</> </div>
Value for ${obj.message} will be 'true' or 'false'. All works fine when the value is TRUE. But, when the value is FALSE, sightly completely removes the attribute 'd-automode' and the resulting HTML is as below:
<div> <p>Content goes here</> </div>
Can someone please provide a solution on how to set value of 'false' fro this attribute?
Thanks,
Solved! Go to Solution.
Views
Replies
Total Likes
This is indeed a current limitation, as the falsy values (including the literal 'false') are triggering the removal of the attribute.
One workaround is:
<div attr="false" data-sly-unwrap="${obj.message}"> <div attr="true" data-sly-unwrap="${!obj.message}"> <p>Contents here</p> </div> </div>
Views
Replies
Total Likes
Can you try this?
<div data-sly-test.message="${'false'}"></div>
${message}
<div d-automode="${message ? 'true' : ' false '}">
<p>Content goes here</>
</div>
Mind the spaces around false.
Views
Replies
Total Likes
Sorry Feike,
FALSE value with space is not the solution. I'm using an API here which reads the value for this attribute and perform actions based on this. API expects the value true or false and not false with space.
Is there any other way of solving this issue? Or is it a bug?
Thanks,
-A
Views
Replies
Total Likes
Thanks Feike for the response.
I have already tried this before as well.
<div data-sly-test.message="${'false'}"></div> ---> No DIV elements rendered
${message}
<div d-automode="${message ? 'true' : ' false '}">
<p>Content goes here</>
</div>
Output is
false
<div d-automode=" false ">
<p>Content goes here</>
</div>
Views
Replies
Total Likes
This is indeed a current limitation, as the falsy values (including the literal 'false') are triggering the removal of the attribute.
One workaround is:
<div attr="false" data-sly-unwrap="${obj.message}"> <div attr="true" data-sly-unwrap="${!obj.message}"> <p>Contents here</p> </div> </div>
Views
Replies
Total Likes
Thanks Catalin for the workaround.
Do you have any workaround if there are multiple boolean attributes as below?
<div d-automode="${obj.message}" d-controls="${obj.controls}"> <p>Content goes here</> </div>
-A
Views
Replies
Total Likes