Skip to content

Commit

Permalink
Minor fix and performance improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
victorybiz committed Sep 26, 2023
1 parent b4540b6 commit 2f1dd56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion public/js/laravel-tel-input.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions resources/js/laravel-tel-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@
}

// Listen the tel inputs events
telInput.removeEventListener('countrychange', countryChangeEventFunc);
telInput.addEventListener('countrychange', countryChangeEventFunc);
telInput.removeEventListener('change', telInputChangeEventFunc);
telInput.addEventListener('change', telInputChangeEventFunc);

// listen and sync phone number with tel input if any
Expand All @@ -225,21 +227,25 @@
if (oldValue != '' && oldValue.charAt(0) != '+' && oldValue.charAt(0) != '0') {
oldValue = `+${oldValue}`;
}
phoneInput.addEventListener('change', function () {
const changeHandler = function () {
let newValue = this.value?.trim();
if (newValue != oldValue && newValue != '') {
itiPhone.setNumber(newValue);
}
});
}
phoneInput.removeEventListener('change', changeHandler);
phoneInput.addEventListener('change', changeHandler);
}
}
// listen and sync phone country with tel input if any
if (telInput.dataset.phoneCountryInput) {
const phoneCountryInput = document.querySelector(telInput.dataset.phoneCountryInput);
if (phoneCountryInput) {
phoneCountryInput.addEventListener('change', function () {
const changeHandler = function () {
itiPhone.setCountry(this.value?.trim());
});
}
phoneCountryInput.removeEventListener('change', changeHandler);
phoneCountryInput.addEventListener('change', changeHandler);
}
}

Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/laravel-tel-input.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{{-- Hidden phone input --}}
<input
type="hidden"
{{ $attributes->wire('model') }}
id="{{ $id }}"
name="{{ $name }}"
@if ($attributes->whereStartsWith('wire:model')->first())
{{ $attributes->wire('model') }}
@endif
@if ($attributes->has('value'))
value="{{ $attributes->get('value') }}"
@endif
Expand Down

0 comments on commit 2f1dd56

Please sign in to comment.