Skip to content

Commit

Permalink
Fix Firefox refresh bug
Browse files Browse the repository at this point in the history
fix firefox bug: when first load page (with input with value set to number with intl dial
code) and initialising plugin removes the dial code from the input, then refresh page,
and we try to init plugin again but this time on number without dial code so get grey flag
  • Loading branch information
jackocnr committed Feb 7, 2021
1 parent 9e93573 commit 40e508c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
8 changes: 7 additions & 1 deletion build/js/intlTelInput-jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,13 @@
}, {
key: "_setInitialState",
value: function _setInitialState() {
var val = this.telInput.value;
// fix firefox bug: when first load page (with input with value set to number with intl dial
// code) and initialising plugin removes the dial code from the input, then refresh page,
// and we try to init plugin again but this time on number without dial code so get grey flag
var attributeValue = this.telInput.getAttribute("value");
var inputValue = this.telInput.value;
var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
var val = useAttribute ? attributeValue : inputValue;
var dialCode = this._getDialCode(val);
var isRegionlessNanp = this._isRegionlessNanp(val);
var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode;
Expand Down
4 changes: 2 additions & 2 deletions build/js/intlTelInput-jquery.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,13 @@
}, {
key: "_setInitialState",
value: function _setInitialState() {
var val = this.telInput.value;
// fix firefox bug: when first load page (with input with value set to number with intl dial
// code) and initialising plugin removes the dial code from the input, then refresh page,
// and we try to init plugin again but this time on number without dial code so get grey flag
var attributeValue = this.telInput.getAttribute("value");
var inputValue = this.telInput.value;
var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
var val = useAttribute ? attributeValue : inputValue;
var dialCode = this._getDialCode(val);
var isRegionlessNanp = this._isRegionlessNanp(val);
var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode;
Expand Down
4 changes: 2 additions & 2 deletions build/js/intlTelInput.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,13 @@ class Iti {
// 3. picking the first preferred country
// 4. picking the first country
_setInitialState() {
const val = this.telInput.value;
// fix firefox bug: when first load page (with input with value set to number with intl dial
// code) and initialising plugin removes the dial code from the input, then refresh page,
// and we try to init plugin again but this time on number without dial code so get grey flag
const attributeValue = this.telInput.getAttribute('value');
const inputValue = this.telInput.value;
const useAttribute = (attributeValue && attributeValue.charAt(0) === '+' && (!inputValue || inputValue.charAt(0) !== '+'));
const val = useAttribute ? attributeValue : inputValue;
const dialCode = this._getDialCode(val);
const isRegionlessNanp = this._isRegionlessNanp(val);
const {
Expand Down

0 comments on commit 40e508c

Please # to comment.