a258f1a66b
Refactor libphonenumber.validateNumber into libphonenumber.parseNumber, which encapsulates the try-catch pattern used in number parsing and returns an object of info about the input number rather tha throwing since we expect to get some invalid number inputs the user is typing. In the conversation model, * Separate phone number validation from search token updating. * Perform token update before save if the number was valid. * Stop storing unneeded number variants as conversation properties. // FREEBIE
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
/*
|
|
* vim: ts=4:sw=4:expandtab
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
Whisper.PhoneInputView = Whisper.View.extend({
|
|
tagName: 'div',
|
|
className: 'phone-input',
|
|
template: $('#phone-number').html(),
|
|
render: function() {
|
|
this.$el.html($(Mustache.render(this.template)));
|
|
this.$('input.number').intlTelInput();
|
|
return this;
|
|
},
|
|
|
|
events: {
|
|
'change': 'validateNumber',
|
|
'keyup': 'validateNumber'
|
|
},
|
|
|
|
validateNumber: function() {
|
|
var input = this.$('input.number');
|
|
var regionCode = this.$('li.active').attr('data-country-code').toUpperCase();
|
|
var number = input.val();
|
|
|
|
var parsedNumber = libphonenumber.util.parseNumber(number, regionCode);
|
|
if (parsedNumber.isValidNumber) {
|
|
this.$('.number-container').removeClass('invalid');
|
|
this.$('.number-container').addClass('valid');
|
|
return parsedNumber.e164;
|
|
} else {
|
|
this.$('.number-container').removeClass('valid');
|
|
}
|
|
input.trigger('validation');
|
|
}
|
|
});
|
|
})();
|