Skip to content

Commit

Permalink
Merge pull request #64 from LM450N/21-expose-computed-international-v…
Browse files Browse the repository at this point in the history
…alue

Expose international format value
  • Loading branch information
notwaldorf authored Aug 10, 2016
2 parents 7879aac + a0ca8cc commit 6a5f949
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions gold-phone-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
value: {
type: String,
observer: '_onValueChanged'
},

/**
* International format of the input value.
*
* @type {String}
*/
internationalValue: {
type: String,
computed: '_computeInternationalValue(countryCode, value)'
}
},

Expand Down Expand Up @@ -254,6 +264,16 @@
if (!focused) {
this._handleAutoValidate();
}
},

/**
* Returns the phone number value prefixed by the country code or simply
* the value if the country code is not set. When `value` equals
* "3-44-55-66-77" and the `countryCode` is "33", the `internationalValue`
* equals "+(33)3-44-55-66-77"
*/
_computeInternationalValue: function(countryCode, value) {
return countryCode ? '+(' + countryCode + ')' + value : value;
}
});

Expand Down
25 changes: 25 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@
assert.notEqual(getComputedStyle(error).visibility, 'hidden', 'error is not visibility:hidden');
assert.isTrue(container.invalid);
});

test('international value properly computed', function() {
var input = fixture('basic');
input.countryCode = '33';
input.phoneNumberPattern = 'X-XX-XX-XX-XX';
input.value = '123456789';
assert.equal(input.internationalValue, '+(33)1-23-45-67-89');
});

test('international value is read only', function() {
var input = fixture('basic');
input.countryCode = '33';
input.phoneNumberPattern = 'X-XX-XX-XX-XX';
input.value = '123456789';
input.internationalValue = '+(32)2-345-67-89';
assert.equal(input.internationalValue, '+(33)1-23-45-67-89');
});

test('gets the value without country code if it is not set', function() {
var input = fixture('basic');
input.countryCode = '';
input.phoneNumberPattern = 'X-XX-XX-XX-XX';
input.value = '123456789';
assert.equal(input.internationalValue, '1-23-45-67-89');
});
});

suite('a11y', function() {
Expand Down

0 comments on commit 6a5f949

Please sign in to comment.