user2402616
user2402616

Reputation: 1563

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!

Upvotes: 0

Views: 43

Answers (1)

Christian Fritz
Christian Fritz

Reputation: 21384

This is where you need to use a so-called attribute helper.

<textarea {{attributes}}>{{foo}}</textarea>
Template.foo.helpers({
  attributes() {
    return {
      disabled: allowed,
    };
  }
});

Upvotes: 3

Related Questions