6

I want to add class in ko template

In js:

define([
        'jquery',
        'ko',
        'uiComponent',
        'underscore',
        'mage/translate',
        'mage/storage',
        'Magento_Checkout/js/model/url-builder',
        'Magento_Customer/js/model/customer',
        'Magento_Checkout/js/model/quote',
        'Magento_Checkout/js/checkout-data'
    ], function ($, ko, Component, _, $t, storage, urlBuilder, customer, quote, checkoutData) {
        'use strict';
        return Component.extend({
            errorMessage: ko.observable(false),
            showElement: ko.observable(),

            initialize: function () {
                this._super();
                this.showElement = this.resolveInitialVisibility();
                return this;
            },

            resolveInitialVisibility: function () {
                if (checkoutData.getInputFieldEmailValue() !== '') {
                    return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue();
                }

                return false;
            }
        });
    }
);

I need to add disable class for <div class="col-md-12 pdl0"> if the showElement returns true.

How to do that

Thanks.

1 Answer 1

5

You can use like this:

<div class="col-md-12 pdl0" data-bind="css: {'disable': showElement} ">

or like this:

<div class="col-md-12 pdl0" data-bind="css: showElement ? 'disable' : ''">
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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