2

I want to hide checkbox if amount is 0 otherwise show.

I tried, In html template

  <!-- ko if: isAllowed -->
  <div data-bind="visible: checkBalanceAmount()">
            <!-- ko ifnot: isApplied() -->
            <input type="checkbox" id="apply-credit"
                    class="action"
                    data-bind="click: applyCredit">
                    <label for="apply-credit"><!-- ko i18n: 'Use Store Credits' --><!-- /ko --></label>
                <span></span>                
            <!-- /ko -->
  </div>
  <!-- /ko -->

In js file

  checkBalanceAmount: function (amount) {
        if(amount > 0)
            balance_amount = 'success';
        else
            balance_amount = '';
        return balance_amount;                        
    }
3

You need to return boolean value to show/hide your condition,

visible consider boolean value to work as expected for ko.

checkBalanceAmount: function (amount) {
        if(amount > 0)
            balance_amount = true;
        else
            balance_amount = false;
        return balance_amount;                        
    }
0

in your code u are using an string as boolean which is not acceptable. You need to change the return type of your js function from string to boolean and then in data-bind, visible will get the input as true or false and will work accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.