hamlbars
hamlbars copied to clipboard
How to pass variable in to disable input?
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"
.
Try:
%button{bind: {disabled: 'isDisabled'}}
Gives the same issue. I'm using https://github.com/leshill/handlebars_assets to compile, but it still uses this engine.
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
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.