I want to disable an HTML button conditionally in a HEEX template. Currently I am doing this:
<%= if @valid_sheet do %>
<button phx-click="save" name="save" value={@sheet_id}>
Save
</button>
<% else %>
<button phx-click="save" name="save" value={@sheet_id} disabled>
Save
</button>
<% end %>
But I would rather just write a button into my html code only once and merely add the disabled attribute conditionally, as follows:
<button phx-click="save" name="save" value={@sheet_id} {if not @valid_sheet, do: "disabled"}>
Save
</button>
But it gives me this error: “Enumerable not implemented for “disabled” of type BitString”
How can I conditionally add an attribute to an html element?