cancel
Showing results for 
Search instead for 
Did you mean: 

Adding events to input on checkout

Adding events to input on checkout

I'm trying to add an event like 'keyup: validationSuccess' to all input fields on the checkout. I have overwritten input.html and added the Js to Shipping.js but now when i go to checkout/cart.html I get an error because of course the validationSuccess function doesn't exist on the Cart JS. So I need the function on all inputs on the Checkout but not on the Cart so overwriting input doesn't work. How do I do this the right way?

2 REPLIES 2

Re: Adding events to input on checkout

You can do it in your overriden input.html file be setting conditions,

Final code will be,

<!-- ko if: window.checkoutConfig.checkoutUrl.replace(/(\/#|\/|#)$/, '') == window.location.href -->
    <!-- for checkout page -->
    <input class="input-text aaaaaaaa" type="text" data-bind="
    value: value,
    valueUpdate: 'keyup',
    hasFocus: focused,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': getDescriptionId(),
        'aria-required': required,
        'aria-invalid': error() ? true : 'false',
        id: uid,
        disabled: disabled
    }" />
<!-- /ko -->
<!-- ko ifnot: window.checkoutConfig.checkoutUrl.replace(/(\/#|\/|#)$/, '') == window.location.href -->
    <!-- for other pages -->
    <input class="input-text aaaaaaaa" type="text" data-bind="
    value: value,
    valueUpdate: 'keyup',
    hasFocus: focused,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': getDescriptionId(),
        'aria-required': required,
        'aria-invalid': error() ? true : 'false',
        id: uid,
        disabled: disabled
    }" />
<!-- /ko -->

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Adding events to input on checkout

I feel like there should be a better way using events and observables but i'm not sure what event get's fired on keyup?