Vinod
Vinod

Reputation: 2311

Issue with checked checkbox in Liferay/Alloy UI

I have a form which has the checkbox. I am saving the check box value as true/false based on selecting of the check box. If I open the form in a edit mode, I am able to get the value from DB as true or false. Now I get the value as true I need to show the checked checkbox in my form OR If the value is false then I need to show the unchecked checkbox. please give me some suggestions.

<%= user.isadmin() %> // here I am getting either true or false

Based on above value I need to check or uncheck the check box,

<aui:input type="checkbox" name="isadmin" label="Is Admin"></aui:input>

If I use,

 <aui:input type="checkbox" name="isadmin" label="Is Admin" checked="<%= user.isadmin()>"></aui:input>

Though user.isadmin() value is true, I am getting an error.

Upvotes: 1

Views: 2979

Answers (1)

Parkash Kumar
Parkash Kumar

Reputation: 4730

Use following way for checking checkbox based on the value of user.isadmin()

<% String checked = user.isadmin() ? "checked" : "" %>
<aui:input type="checkbox" name="isadmin" label="Is Admin" <%=checked %>></aui:input>

Upvotes: 0

Related Questions