Magento 2 checkout knockout.js in custom template error - telephone fieldOverriding template files in own theme, loaded through JS (Knockout.js)Change the telephone field from 'Telephone' to only 'Mobile Number' at CheckoutMagento 2 EE Checkout Page not working (JS error)Knockout.js breaks in /checkout in my themeMagento 2.2.1: Add Custom Upload file attribute in Checkoutadd custom js to the certain input element on the checkout pageMagento 2.2.1 : Add Custom Field in Login Form On Checkout PageMagento 2 | Remove telephone from checkout addressHow to add custom validation to checkout phone fieldRequire custom checkout field from extension

Why is the voltage measurement of this circuit different when the switch is on?

How to split an equation over two lines?

Distance Matrix (plugin) - QGIS

Impossible darts scores

Alphabet completion rate

How can I repair scratches on a painted French door?

How risky is real estate?

Could Sauron have read Tom Bombadil's mind if Tom had held the Palantir?

Can ADFS connect to other SSO services?

How to get cool night-vision without lame drawbacks?

Story-based adventure with functions and relationships

Can the negators "jamais, rien, personne, plus, ni, aucun" be used in a single sentence?

No IMPLICIT_CONVERSION warning in this query plan

Is this one of the engines from the 9/11 aircraft?

Does the posterior necessarily follow the same conditional dependence structure as the prior?

Why do textbooks often include the solutions to odd or even numbered problems but not both?

What do you call a weak person's act of taking on bigger opponents?

Using “sparkling” as a diminutive of “spark” in a poem

Fedora boot screen shows both Fedora logo and Lenovo logo. Why and How?

Would a two-seat light aircaft with a landing speed of 20 knots and a top speed of 180 knots be technically possible?

Can’t attend PhD conferences

Why does the numerical solution of an ODE move away from an unstable equilibrium?

How well known and how commonly used was Huffman coding in 1979?

Importance of the principal bundle in Chern-Simons theory



Magento 2 checkout knockout.js in custom template error - telephone field


Overriding template files in own theme, loaded through JS (Knockout.js)Change the telephone field from 'Telephone' to only 'Mobile Number' at CheckoutMagento 2 EE Checkout Page not working (JS error)Knockout.js breaks in /checkout in my themeMagento 2.2.1: Add Custom Upload file attribute in Checkoutadd custom js to the certain input element on the checkout pageMagento 2.2.1 : Add Custom Field in Login Form On Checkout PageMagento 2 | Remove telephone from checkout addressHow to add custom validation to checkout phone fieldRequire custom checkout field from extension






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm trying to create a mask for telephone field in Magento 2.2.2 checkout. In order to do so. I placed a checkout_index_index.xml with a new template for telephone field at



vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



 <?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<!-- The name of the form the field belongs to -->
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<!-- the field you are customizing -->
<item name="telephone" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
<item name="config" xsi:type="array">
<!-- Assigning a new template -->

<item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>

</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>


In the folder vendor/mytheme/web/js/view/masked.js I place bellow code



define(['jquery', 'uiComponent', 'ko', ], function ( $, Component, ko) 
'use strict';
return Component.extend(
defaults:
template: 'Magento_Checkout/telefone'
,
initialize: function ()
var self = this;
this._super();
ko.bindingHandlers.maskedInput =
init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
,
update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
$(element).mask(allBindings.get('mask'));
valueAccessor()($(element).val());

;

var ViewModel = function()

this.phone = ko.observable("");


this.phone('123123451212');
;
ko.applyBindings(new ViewModel());



)

);


And the I created template telefone.html at vendor/mytheme/Magento_Checkout/web/template



<input class="input-text" type="text" data-bind="
value: value,
valueUpdate: 'keyup',
maskedInput: phone,
mask: '(999) 999-9999',
hasFocus: focused,
attr:
name: inputName,
placeholder: placeholder,
'aria-describedby': noticeId,
id: uid,
disabled: disabled
" />


But when I go to checkout I get error: Uncaught Error: You cannot apply bindings multiple times to the same element. Does someone know a proper way to apply phone mask to telephone input at checkout. Or, if my method is correct, what am I missing or doing wrong?










share|improve this question
























  • When you use component there is no need to applyBindings on it.It will do it automatically

    – Zaheerabbas
    Apr 13 '18 at 14:04











  • I removed " ko.applyBindings(new ViewModel());" and now I get ReferenceError: Unable to process binding "css: function ()return additionalClasses " Message: Can't find variable: additionalClasses

    – Gabriela
    Apr 13 '18 at 14:54











  • @Gabriela, Have you got any solution for this?

    – Pushpendra Singh
    Jun 22 '18 at 9:48











  • Sorry, I didn't find a solution. If you have any, please post it here.

    – Gabriela
    Jun 29 '18 at 13:05

















0















I'm trying to create a mask for telephone field in Magento 2.2.2 checkout. In order to do so. I placed a checkout_index_index.xml with a new template for telephone field at



vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



 <?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<!-- The name of the form the field belongs to -->
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<!-- the field you are customizing -->
<item name="telephone" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
<item name="config" xsi:type="array">
<!-- Assigning a new template -->

<item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>

</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>


In the folder vendor/mytheme/web/js/view/masked.js I place bellow code



define(['jquery', 'uiComponent', 'ko', ], function ( $, Component, ko) 
'use strict';
return Component.extend(
defaults:
template: 'Magento_Checkout/telefone'
,
initialize: function ()
var self = this;
this._super();
ko.bindingHandlers.maskedInput =
init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
,
update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
$(element).mask(allBindings.get('mask'));
valueAccessor()($(element).val());

;

var ViewModel = function()

this.phone = ko.observable("");


this.phone('123123451212');
;
ko.applyBindings(new ViewModel());



)

);


And the I created template telefone.html at vendor/mytheme/Magento_Checkout/web/template



<input class="input-text" type="text" data-bind="
value: value,
valueUpdate: 'keyup',
maskedInput: phone,
mask: '(999) 999-9999',
hasFocus: focused,
attr:
name: inputName,
placeholder: placeholder,
'aria-describedby': noticeId,
id: uid,
disabled: disabled
" />


But when I go to checkout I get error: Uncaught Error: You cannot apply bindings multiple times to the same element. Does someone know a proper way to apply phone mask to telephone input at checkout. Or, if my method is correct, what am I missing or doing wrong?










share|improve this question
























  • When you use component there is no need to applyBindings on it.It will do it automatically

    – Zaheerabbas
    Apr 13 '18 at 14:04











  • I removed " ko.applyBindings(new ViewModel());" and now I get ReferenceError: Unable to process binding "css: function ()return additionalClasses " Message: Can't find variable: additionalClasses

    – Gabriela
    Apr 13 '18 at 14:54











  • @Gabriela, Have you got any solution for this?

    – Pushpendra Singh
    Jun 22 '18 at 9:48











  • Sorry, I didn't find a solution. If you have any, please post it here.

    – Gabriela
    Jun 29 '18 at 13:05













0












0








0








I'm trying to create a mask for telephone field in Magento 2.2.2 checkout. In order to do so. I placed a checkout_index_index.xml with a new template for telephone field at



vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



 <?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<!-- The name of the form the field belongs to -->
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<!-- the field you are customizing -->
<item name="telephone" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
<item name="config" xsi:type="array">
<!-- Assigning a new template -->

<item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>

</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>


In the folder vendor/mytheme/web/js/view/masked.js I place bellow code



define(['jquery', 'uiComponent', 'ko', ], function ( $, Component, ko) 
'use strict';
return Component.extend(
defaults:
template: 'Magento_Checkout/telefone'
,
initialize: function ()
var self = this;
this._super();
ko.bindingHandlers.maskedInput =
init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
,
update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
$(element).mask(allBindings.get('mask'));
valueAccessor()($(element).val());

;

var ViewModel = function()

this.phone = ko.observable("");


this.phone('123123451212');
;
ko.applyBindings(new ViewModel());



)

);


And the I created template telefone.html at vendor/mytheme/Magento_Checkout/web/template



<input class="input-text" type="text" data-bind="
value: value,
valueUpdate: 'keyup',
maskedInput: phone,
mask: '(999) 999-9999',
hasFocus: focused,
attr:
name: inputName,
placeholder: placeholder,
'aria-describedby': noticeId,
id: uid,
disabled: disabled
" />


But when I go to checkout I get error: Uncaught Error: You cannot apply bindings multiple times to the same element. Does someone know a proper way to apply phone mask to telephone input at checkout. Or, if my method is correct, what am I missing or doing wrong?










share|improve this question
















I'm trying to create a mask for telephone field in Magento 2.2.2 checkout. In order to do so. I placed a checkout_index_index.xml with a new template for telephone field at



vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



 <?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<!-- The name of the form the field belongs to -->
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<!-- the field you are customizing -->
<item name="telephone" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
<item name="config" xsi:type="array">
<!-- Assigning a new template -->

<item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>

</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>


In the folder vendor/mytheme/web/js/view/masked.js I place bellow code



define(['jquery', 'uiComponent', 'ko', ], function ( $, Component, ko) 
'use strict';
return Component.extend(
defaults:
template: 'Magento_Checkout/telefone'
,
initialize: function ()
var self = this;
this._super();
ko.bindingHandlers.maskedInput =
init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
,
update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
$(element).mask(allBindings.get('mask'));
valueAccessor()($(element).val());

;

var ViewModel = function()

this.phone = ko.observable("");


this.phone('123123451212');
;
ko.applyBindings(new ViewModel());



)

);


And the I created template telefone.html at vendor/mytheme/Magento_Checkout/web/template



<input class="input-text" type="text" data-bind="
value: value,
valueUpdate: 'keyup',
maskedInput: phone,
mask: '(999) 999-9999',
hasFocus: focused,
attr:
name: inputName,
placeholder: placeholder,
'aria-describedby': noticeId,
id: uid,
disabled: disabled
" />


But when I go to checkout I get error: Uncaught Error: You cannot apply bindings multiple times to the same element. Does someone know a proper way to apply phone mask to telephone input at checkout. Or, if my method is correct, what am I missing or doing wrong?







magento2 checkout javascript knockoutjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 5 '18 at 13:46









7ochem

5,9399 gold badges37 silver badges70 bronze badges




5,9399 gold badges37 silver badges70 bronze badges










asked Apr 13 '18 at 13:50









GabrielaGabriela

267 bronze badges




267 bronze badges












  • When you use component there is no need to applyBindings on it.It will do it automatically

    – Zaheerabbas
    Apr 13 '18 at 14:04











  • I removed " ko.applyBindings(new ViewModel());" and now I get ReferenceError: Unable to process binding "css: function ()return additionalClasses " Message: Can't find variable: additionalClasses

    – Gabriela
    Apr 13 '18 at 14:54











  • @Gabriela, Have you got any solution for this?

    – Pushpendra Singh
    Jun 22 '18 at 9:48











  • Sorry, I didn't find a solution. If you have any, please post it here.

    – Gabriela
    Jun 29 '18 at 13:05

















  • When you use component there is no need to applyBindings on it.It will do it automatically

    – Zaheerabbas
    Apr 13 '18 at 14:04











  • I removed " ko.applyBindings(new ViewModel());" and now I get ReferenceError: Unable to process binding "css: function ()return additionalClasses " Message: Can't find variable: additionalClasses

    – Gabriela
    Apr 13 '18 at 14:54











  • @Gabriela, Have you got any solution for this?

    – Pushpendra Singh
    Jun 22 '18 at 9:48











  • Sorry, I didn't find a solution. If you have any, please post it here.

    – Gabriela
    Jun 29 '18 at 13:05
















When you use component there is no need to applyBindings on it.It will do it automatically

– Zaheerabbas
Apr 13 '18 at 14:04





When you use component there is no need to applyBindings on it.It will do it automatically

– Zaheerabbas
Apr 13 '18 at 14:04













I removed " ko.applyBindings(new ViewModel());" and now I get ReferenceError: Unable to process binding "css: function ()return additionalClasses " Message: Can't find variable: additionalClasses

– Gabriela
Apr 13 '18 at 14:54





I removed " ko.applyBindings(new ViewModel());" and now I get ReferenceError: Unable to process binding "css: function ()return additionalClasses " Message: Can't find variable: additionalClasses

– Gabriela
Apr 13 '18 at 14:54













@Gabriela, Have you got any solution for this?

– Pushpendra Singh
Jun 22 '18 at 9:48





@Gabriela, Have you got any solution for this?

– Pushpendra Singh
Jun 22 '18 at 9:48













Sorry, I didn't find a solution. If you have any, please post it here.

– Gabriela
Jun 29 '18 at 13:05





Sorry, I didn't find a solution. If you have any, please post it here.

– Gabriela
Jun 29 '18 at 13:05










2 Answers
2






active

oldest

votes


















0














There is seems to be a conflict because below layout you have already mentioned the template of element and re-defined the template in your component js file also,



vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



<!-- the field you are customizing -->
<item name="telephone" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
<item name="config" xsi:type="array">
<!-- Assigning a new template -->
<item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>
</item>
</item>


Hence try replace below component script with your,
vendor/mytheme/web/js/view/masked.js



define([
'underscore', 'ko',
'mageUtils',
'Magento_Ui/js/form/element/abstract',
'uiLayout'
], function (_, ko, utils, Abstract, layout)
'use strict';

return Abstract.extend(
initialize: function ()
this._super();

//add your custom code or call custom functions
ko.bindingHandlers.maskedInput =
init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
,
update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
$(element).mask(allBindings.get('mask'));
valueAccessor()($(element).val());

;

var ViewModel = function()
this.phone = ko.observable("");
this.phone('123123451212');
;
ko.applyBindings(new ViewModel());

return this;

);
);


Note : script extends from Magento_Ui/js/form/element/abstract






share|improve this answer























  • Didn't work either

    – Gabriela
    Oct 8 '18 at 17:23


















0














My goal is just to put a mask for the telephone field in Magento2 Checkout. Since the Knockout method didn't work I simple declared a new template in checkout_index_index.xml with the bellow code:



 <input class="input-text" type="text" placeholder= (__)_____-____ data-bind="
value: value,
valueUpdate: 'keyup',
attr:
name: inputName,
id: uid
" name="telephone" aria-required="true" aria-invalid="false" autocomplete="off" onfocus="this.value='(';" onkeyup="var telephone = this.value;
if (telephone.match(/^(d2$/) !==null)
this.value = telephone + ')';
else if (telephone.match(/^(d2)d5$/) !== null)
this.value = telephone + '-';
" maxlength="14"/>





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f222229%2fmagento-2-checkout-knockout-js-in-custom-template-error-telephone-field%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    There is seems to be a conflict because below layout you have already mentioned the template of element and re-defined the template in your component js file also,



    vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



    <!-- the field you are customizing -->
    <item name="telephone" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
    <item name="config" xsi:type="array">
    <!-- Assigning a new template -->
    <item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>
    </item>
    </item>


    Hence try replace below component script with your,
    vendor/mytheme/web/js/view/masked.js



    define([
    'underscore', 'ko',
    'mageUtils',
    'Magento_Ui/js/form/element/abstract',
    'uiLayout'
    ], function (_, ko, utils, Abstract, layout)
    'use strict';

    return Abstract.extend(
    initialize: function ()
    this._super();

    //add your custom code or call custom functions
    ko.bindingHandlers.maskedInput =
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
    ,
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
    $(element).mask(allBindings.get('mask'));
    valueAccessor()($(element).val());

    ;

    var ViewModel = function()
    this.phone = ko.observable("");
    this.phone('123123451212');
    ;
    ko.applyBindings(new ViewModel());

    return this;

    );
    );


    Note : script extends from Magento_Ui/js/form/element/abstract






    share|improve this answer























    • Didn't work either

      – Gabriela
      Oct 8 '18 at 17:23















    0














    There is seems to be a conflict because below layout you have already mentioned the template of element and re-defined the template in your component js file also,



    vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



    <!-- the field you are customizing -->
    <item name="telephone" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
    <item name="config" xsi:type="array">
    <!-- Assigning a new template -->
    <item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>
    </item>
    </item>


    Hence try replace below component script with your,
    vendor/mytheme/web/js/view/masked.js



    define([
    'underscore', 'ko',
    'mageUtils',
    'Magento_Ui/js/form/element/abstract',
    'uiLayout'
    ], function (_, ko, utils, Abstract, layout)
    'use strict';

    return Abstract.extend(
    initialize: function ()
    this._super();

    //add your custom code or call custom functions
    ko.bindingHandlers.maskedInput =
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
    ,
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
    $(element).mask(allBindings.get('mask'));
    valueAccessor()($(element).val());

    ;

    var ViewModel = function()
    this.phone = ko.observable("");
    this.phone('123123451212');
    ;
    ko.applyBindings(new ViewModel());

    return this;

    );
    );


    Note : script extends from Magento_Ui/js/form/element/abstract






    share|improve this answer























    • Didn't work either

      – Gabriela
      Oct 8 '18 at 17:23













    0












    0








    0







    There is seems to be a conflict because below layout you have already mentioned the template of element and re-defined the template in your component js file also,



    vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



    <!-- the field you are customizing -->
    <item name="telephone" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
    <item name="config" xsi:type="array">
    <!-- Assigning a new template -->
    <item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>
    </item>
    </item>


    Hence try replace below component script with your,
    vendor/mytheme/web/js/view/masked.js



    define([
    'underscore', 'ko',
    'mageUtils',
    'Magento_Ui/js/form/element/abstract',
    'uiLayout'
    ], function (_, ko, utils, Abstract, layout)
    'use strict';

    return Abstract.extend(
    initialize: function ()
    this._super();

    //add your custom code or call custom functions
    ko.bindingHandlers.maskedInput =
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
    ,
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
    $(element).mask(allBindings.get('mask'));
    valueAccessor()($(element).val());

    ;

    var ViewModel = function()
    this.phone = ko.observable("");
    this.phone('123123451212');
    ;
    ko.applyBindings(new ViewModel());

    return this;

    );
    );


    Note : script extends from Magento_Ui/js/form/element/abstract






    share|improve this answer













    There is seems to be a conflict because below layout you have already mentioned the template of element and re-defined the template in your component js file also,



    vendor/mytheme/Magento_Checkout/layout/checkout_index_index.xml



    <!-- the field you are customizing -->
    <item name="telephone" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Checkout/js/view/masked</item>
    <item name="config" xsi:type="array">
    <!-- Assigning a new template -->
    <item name="elementTmpl" xsi:type="string">Magento_Checkout/form/element/telefone</item>
    </item>
    </item>


    Hence try replace below component script with your,
    vendor/mytheme/web/js/view/masked.js



    define([
    'underscore', 'ko',
    'mageUtils',
    'Magento_Ui/js/form/element/abstract',
    'uiLayout'
    ], function (_, ko, utils, Abstract, layout)
    'use strict';

    return Abstract.extend(
    initialize: function ()
    this._super();

    //add your custom code or call custom functions
    ko.bindingHandlers.maskedInput =
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.init(element, valueAccessor, allBindings, viewModel, bindingContext);
    ,
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext)
    ko.bindingHandlers.value.update(element, valueAccessor, allBindings, viewModel, bindingContext);
    $(element).mask(allBindings.get('mask'));
    valueAccessor()($(element).val());

    ;

    var ViewModel = function()
    this.phone = ko.observable("");
    this.phone('123123451212');
    ;
    ko.applyBindings(new ViewModel());

    return this;

    );
    );


    Note : script extends from Magento_Ui/js/form/element/abstract







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 29 '18 at 6:49









    Dasitha AbeysingheDasitha Abeysinghe

    12 bronze badges




    12 bronze badges












    • Didn't work either

      – Gabriela
      Oct 8 '18 at 17:23

















    • Didn't work either

      – Gabriela
      Oct 8 '18 at 17:23
















    Didn't work either

    – Gabriela
    Oct 8 '18 at 17:23





    Didn't work either

    – Gabriela
    Oct 8 '18 at 17:23













    0














    My goal is just to put a mask for the telephone field in Magento2 Checkout. Since the Knockout method didn't work I simple declared a new template in checkout_index_index.xml with the bellow code:



     <input class="input-text" type="text" placeholder= (__)_____-____ data-bind="
    value: value,
    valueUpdate: 'keyup',
    attr:
    name: inputName,
    id: uid
    " name="telephone" aria-required="true" aria-invalid="false" autocomplete="off" onfocus="this.value='(';" onkeyup="var telephone = this.value;
    if (telephone.match(/^(d2$/) !==null)
    this.value = telephone + ')';
    else if (telephone.match(/^(d2)d5$/) !== null)
    this.value = telephone + '-';
    " maxlength="14"/>





    share|improve this answer



























      0














      My goal is just to put a mask for the telephone field in Magento2 Checkout. Since the Knockout method didn't work I simple declared a new template in checkout_index_index.xml with the bellow code:



       <input class="input-text" type="text" placeholder= (__)_____-____ data-bind="
      value: value,
      valueUpdate: 'keyup',
      attr:
      name: inputName,
      id: uid
      " name="telephone" aria-required="true" aria-invalid="false" autocomplete="off" onfocus="this.value='(';" onkeyup="var telephone = this.value;
      if (telephone.match(/^(d2$/) !==null)
      this.value = telephone + ')';
      else if (telephone.match(/^(d2)d5$/) !== null)
      this.value = telephone + '-';
      " maxlength="14"/>





      share|improve this answer

























        0












        0








        0







        My goal is just to put a mask for the telephone field in Magento2 Checkout. Since the Knockout method didn't work I simple declared a new template in checkout_index_index.xml with the bellow code:



         <input class="input-text" type="text" placeholder= (__)_____-____ data-bind="
        value: value,
        valueUpdate: 'keyup',
        attr:
        name: inputName,
        id: uid
        " name="telephone" aria-required="true" aria-invalid="false" autocomplete="off" onfocus="this.value='(';" onkeyup="var telephone = this.value;
        if (telephone.match(/^(d2$/) !==null)
        this.value = telephone + ')';
        else if (telephone.match(/^(d2)d5$/) !== null)
        this.value = telephone + '-';
        " maxlength="14"/>





        share|improve this answer













        My goal is just to put a mask for the telephone field in Magento2 Checkout. Since the Knockout method didn't work I simple declared a new template in checkout_index_index.xml with the bellow code:



         <input class="input-text" type="text" placeholder= (__)_____-____ data-bind="
        value: value,
        valueUpdate: 'keyup',
        attr:
        name: inputName,
        id: uid
        " name="telephone" aria-required="true" aria-invalid="false" autocomplete="off" onfocus="this.value='(';" onkeyup="var telephone = this.value;
        if (telephone.match(/^(d2$/) !==null)
        this.value = telephone + ')';
        else if (telephone.match(/^(d2)d5$/) !== null)
        this.value = telephone + '-';
        " maxlength="14"/>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 9 '18 at 1:47









        GabrielaGabriela

        267 bronze badges




        267 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f222229%2fmagento-2-checkout-knockout-js-in-custom-template-error-telephone-field%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form