Bao Tran Hoang

How to update phone number format on key input

Discussion created by Bao Tran Hoang on Mar 2, 2017
Latest reply on Mar 2, 2017 by Bao Tran Hoang

I want to update the phone number format on user key in the phone work field

I created /custom/modules/Contacts/client/base/fields/phone/phone.js

.

({
extendsFrom: 'PhoneField',

events: {
'keyup input[name="phone_work"]': 'formatAsPhoneNumber'
},

initialize: function (options) {
this._super('initialize', [options]);
},

formatAsPhoneNumber: function(){
var value = this.$(this.fieldTag).val();

// do whatever you want to phoneNumber
value=value.substr(0,3)+'-'+value.substr(3,3)+'-'+value.substr(6,4);
this.$(this.fieldTag).val(value);
}
})

 

It does not work, please help me

 

Thanks

Outcomes