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?
1 Answer
Instead of adding new events you can subscribe to each input value as all those are knockoutjs observable elements
-
Do you maybe have an example of how I would to something like that?Sanne– Sanne2018-05-30 09:37:59 +00:00Commented May 30, 2018 at 9:37
-
yes @Sanne this is documented in knockoutjs.com/documentation/observables.htmlAnton S– Anton S2018-05-30 09:43:44 +00:00Commented May 30, 2018 at 9:43
-
Ah thanks, hmm in the docs they do something like 'myViewModel.personName()' how would i do something like that in Magento_Checkout/js/view/shipping.js? (i made a mixin for it) I'm unsure what how i could access the view model for that js.Sanne– Sanne2018-05-30 10:03:40 +00:00Commented May 30, 2018 at 10:03
-
I did see that you can access this.source.shippingAddress.firstname but i'm not sure if that is exactly what you mean?Sanne– Sanne2018-05-30 10:17:04 +00:00Commented May 30, 2018 at 10:17
-
you can subscribe to this input and get to know whenever value changesAnton S– Anton S2018-06-06 08:00:07 +00:00Commented Jun 6, 2018 at 8:00