Sightly - Not able to assign value 'false' to a div property | Community
Skip to main content
Level 3
October 16, 2015
Solved

Sightly - Not able to assign value 'false' to a div property

  • October 16, 2015
  • 5 replies
  • 3600 views

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,

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 CatalinB

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>

5 replies

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

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.

ashtrickAuthor
Level 3
October 16, 2015

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

ashtrickAuthor
Level 3
October 16, 2015

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="&#x20;false&#x20;">

    <p>Content goes here</>

</div>

CatalinBAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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>
ashtrickAuthor
Level 3
October 16, 2015

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