Unable to process binding click: function()

by MadzQuestioning   Last Updated May 15, 2019 20:09 PM

I'm trying to implement a click event in one of the button I added under the Magento_Checkout module specifically under payment.html view. Now I added the below code

File location: app/design/frontend/Vendor/Module/Magento_Checkout/web/template/payment.html

<form id="co-payment-form" class="form payments" novalidate="novalidate">
    <fieldset class="fieldset">              
        <button type="button" data-bind="click: goBackShipping">Back from template</button>
    </fieldset>
</form>

Now what I want is that the goBackShipping will be triggered using KnockoutJS functionality. But I'm getting this error

knockout.js:3391 Uncaught ReferenceError: Unable to process binding "click: function(){return goBackShipping }"

This goBackShipping function is added in the checkout-data.js under the folder

app/design/frontend/Vendor/Module/Magento_Checkout/web/js/checkout-data.js

and here is the code I added

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

 /**
  * Checkout adapter for customer data storage
  *
  * @api
  */
 define([
     'jquery',
     'Magento_Customer/js/customer-data',
     'jquery/jquery-storageapi'
 ], function ($, storage) {
     'use strict';

    var cacheKey = 'checkout-data',

    /**
     * @param {Object} data
     */
    saveData = function (data) {
        storage.set(cacheKey, data);
    },

   // This is the newly added function
    goBackShipping = function () {
        alert("Preparing to go back");
        window.history.back();
    },

    /**
     * @return {*}
     */
    initData = function () {

        return { ... };
    },
  };
});

Honestly I have no idea why it's giving an error like that. Am I doing something wrong? (obviously yes because it's giving an error).

I would only like to implement a button click action using knockoutjs and simple javascript alert. But I can't get pass this error.



Related Questions


Updated February 29, 2016 03:04 AM

Updated November 28, 2016 08:03 AM

Updated July 24, 2016 08:03 AM

Updated May 31, 2017 07:09 AM

Updated September 21, 2016 09:03 AM