Spacebars for HTML 'disabled' HTML input


I’m disabling textareas using the disabled HTML property.

<textarea disabled>{{foo}}</textarea>

Simple enough. That enables it so that the client cannot enter the textarea and make changes. However, I want to make that disabled based on a conditional.

Let’s say allowed is a Boolean. I want to just be able to do the following.

<textarea {{#unless allowed}} disabled  {{/unless}}>{{foo}}</textarea>

But this causes errors in the template. In VS Code the {{#unless allowed}}disabled{{ turns blue and the /unless}} turns red.

Any idea on how to do this? Thanks!

You can pass a boolean to disabled to toggle it:

<textarea disabled="{{not allowed}}">{{foo}}</textarea>

You’ll want a not helper to make my example work, or use an disallowed helper

1 Like