Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

How to pass variable in to disable input? #52

Open
rpocklin opened this issue Oct 22, 2013 · 4 comments
Open

How to pass variable in to disable input? #52

rpocklin opened this issue Oct 22, 2013 · 4 comments

Comments

@rpocklin
Copy link

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".

@jimsynz
Copy link
Owner

jimsynz commented Oct 22, 2013

Try:

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

@rpocklin
Copy link
Author

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

@jimsynz
Copy link
Owner

jimsynz commented Oct 24, 2013

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

@rpocklin
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants