0

I am trying to disable a certain option of select generated from knockout on the checkout page. I tried what was mentioned on the knockout documentation i.e. to call optionsAfterRender. But this gives error and I think magento provides AfterRender for this, but the function example provided on the official documentation does not work.

the following code does not work to my expectations i.e. to disable certain option.

setOptionsDisable: function (option, item) {
            ko.applyBindingsToNode(option, {disable: item.disable}, item);
        },

Although I have also added disable: ko.observable(true) to the observable array as key|value.

So, how do I disable the option once it's been rendered? I don't think it can be disabled while rendering.

1 Answer 1

0

If this is a core option, or an option that's been added yourself to checkout via layout - it can be disabled via layout. See devdocs below:

You will have to find the node for the element in checkout_index_index.xml and mark it a disabled as per docs.

1
  • e.g. I am getting list of all coupons and creating a dropdown using knockout, but now I also want to disable the option of coupon that was used. in PHP I could achieve this by simple if condition. But how do I do this in ko in magento? by default its possible in knockout however, how to do it in magento?
    – nix
    Commented Jan 27, 2022 at 17:32

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.