hamlbars icon indicating copy to clipboard operation
hamlbars copied to clipboard

How to pass variable in to disable input?

Open rpocklin opened this issue 11 years ago • 4 comments

With normal HAML, you can disable inputs in the definition by doing: %button{:disabled => disabled ? true : nil} but in Hamlbars I can't see a way to achieve the same.

I have resorted to <button {{#if disabled}}disabled{{/if}}> which kind of defeats the purpose of using hamlbars - is there any way to achieve this? Part of the problem is browsers intepret disabled="" or disabled="false" as disabled="disabled".

rpocklin avatar Oct 22 '13 21:10 rpocklin

Try:

%button{bind: {disabled: 'isDisabled'}}

jimsynz avatar Oct 22 '13 21:10 jimsynz

Gives the same issue. I'm using https://github.com/leshill/handlebars_assets to compile, but it still uses this engine.

rpocklin avatar Oct 23 '13 08:10 rpocklin

Ah! I thought you were using Ember. If you just want a handlebars expression you can just do:

%button{hb: 'disabledAttr'}

and make the disabledAttr helper return something like "disabled" or "" depending on the state.

However, this won't work for you if you want an if statement. In that case I'd suggest something more like:

=hb 'if disabled' do
  %button{disabled: true}
  =hb 'else'
  %button

jimsynz avatar Oct 24 '13 21:10 jimsynz

Thanks - that will work, but means I have to repeat everything else i've defined in the %button tag :(

I might go back to HTML + Handlebars.js - the hb helper feels like a 3rd language I don't want to deal with.

rpocklin avatar Oct 24 '13 22:10 rpocklin