Search code examples
data-bindingknockout.jsknockout-3.0

KnockoutJS and conditional custom binding


I have custom KnockoutJS data binding which looks like

<a class="btn single ok" title="OK" tabindex="5" 
   data-bind="command: loginUser, 
   css: { disabled: !userSelected(), 'no-disabled': userSelected()}">OK</a>

Is there any way to make command binding conditional as well so when !userSelected() then is not executed? Or do I need to that conditional in the command creation code?


Solution

  • Well, I have ended up to checking for userSelected() state in the loginUser function.