Skip to content

Commit

Permalink
Include selected country code with hiddenInput
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Feb 14, 2024
1 parent 20bb2f0 commit 47af197
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 84 deletions.
7 changes: 7 additions & 0 deletions build/js/intlTelInput-jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@
name: hiddenInputName
});
wrapper.appendChild(this.hiddenInput);
// add a 2nd hidden input for the selected country code - this is useful for handling invalid numbers with server-side validation, as getNumber does not always include the international dial code for invalid numbers
this.hiddenInputCountry = this._createEl("input", {
type: "hidden",
name: "".concat(hiddenInputName, "_country")
});
wrapper.appendChild(this.hiddenInputCountry);
}
}
}, {
Expand Down Expand Up @@ -679,6 +685,7 @@
var _this2 = this;
this._handleHiddenInputSubmit = function() {
_this2.hiddenInput.value = _this2.getNumber();
_this2.hiddenInputCountry.value = _this2.getSelectedCountryData().iso2;
};
if (this.telInput.form) {
this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
Expand Down
4 changes: 2 additions & 2 deletions build/js/intlTelInput-jquery.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@
name: hiddenInputName
});
wrapper.appendChild(this.hiddenInput);
// add a 2nd hidden input for the selected country code - this is useful for handling invalid numbers with server-side validation, as getNumber does not always include the international dial code for invalid numbers
this.hiddenInputCountry = this._createEl("input", {
type: "hidden",
name: "".concat(hiddenInputName, "_country")
});
wrapper.appendChild(this.hiddenInputCountry);
}
}
}, {
Expand Down Expand Up @@ -674,6 +680,7 @@
var _this2 = this;
this._handleHiddenInputSubmit = function() {
_this2.hiddenInput.value = _this2.getNumber();
_this2.hiddenInputCountry.value = _this2.getSelectedCountryData().iso2;
};
if (this.telInput.form) {
this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
Expand Down
4 changes: 2 additions & 2 deletions build/js/intlTelInput.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions react/build/IntlTelInput.cjs.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions react/build/IntlTelInput.cjs.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions react/build/IntlTelInput.esm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions react/build/IntlTelInput.esm.js.map

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions react/demo/simple-bundle.js

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions react/demo/validation-bundle.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ class Iti {
name: hiddenInputName
});
wrapper.appendChild(this.hiddenInput);
// add a 2nd hidden input for the selected country code - this is useful for handling invalid numbers with server-side validation, as getNumber does not always include the international dial code for invalid numbers
this.hiddenInputCountry = this._createEl("input", {
type: "hidden",
name: `${hiddenInputName}_country`
});
wrapper.appendChild(this.hiddenInputCountry);
}
}

Expand Down Expand Up @@ -633,6 +639,7 @@ class Iti {
_initHiddenInputListener() {
this._handleHiddenInputSubmit = () => {
this.hiddenInput.value = this.getNumber();
this.hiddenInputCountry.value = this.getSelectedCountryData().iso2;
};
if (this.telInput.form) {
this.telInput.form.addEventListener(
Expand Down

0 comments on commit 47af197

Please sign in to comment.