How to add an attribute without value to a tag? (eg: disabled attribute)

Avatar

Avatar
Level 1
Fathima
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile

Avatar
Level 1
Fathima
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile
Fathima
Level 1

13-10-2020

Hi All,

I want to add the 'disabled' attribute to textarea tag by checking whether the read-only field functionality is enabled or not. If the user wants the textarea to appear as disabled, I have to add the disabled attribute to the textarea tag.

Is it possible to add this attribute without a value? Currently, I use the code:

 

 

<textarea disabled="${properties.disabled}"></textarea>

 

 

But when I use this code, I get my resulting tag look like this in html:

 

 

<textarea disabled="true"></textarea>

 

 

I want the disabled attribute without a value like the below code after checking whether the user had enabled "${properties.disabled}" or not.

 

 

<textarea disabled></textarea>

 

 

Kindly help me figure a way to add the attribute by checking for the condition without adding a value along with the attribute.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

645 likes

Total Posts

607 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

645 likes

Total Posts

607 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

16-10-2020

@Fathima you can achieve this with HTL, Sightly: data-sly-attribute.disabled

<div data-sly-attribute.disabled="${properties.disabled}"></div>

// if true
<div disabled></div>

// if false
<div></div>

 

 

I hope this helps,
Brian. 

Answers (0)