Browse Source

Support country search by its abbreviation

master
Eduard Kuzmenko 3 years ago
parent
commit
ab185b1820
  1. 2
      src/helpers/formatPhoneNumber.ts
  2. 15
      src/pages/pageSignIn.ts

2
src/helpers/formatPhoneNumber.ts

@ -31,8 +31,6 @@ export function formatPhoneNumber(originalStr: string): { @@ -31,8 +31,6 @@ export function formatPhoneNumber(originalStr: string): {
if(!prefixes.size) {
I18n.countriesList.forEach(country => {
country.country_codes.forEach(code => {
const s = {country, code};
if(code.prefixes) {
code.prefixes.forEach(prefix => {
setPrefix(country, code, prefix);

15
src/pages/pageSignIn.ts

@ -244,7 +244,20 @@ let onFirstMount = () => { @@ -244,7 +244,20 @@ let onFirstMount = () => {
let _value = countryInputField.value.toLowerCase();
let matches: HelpCountry[] = [];
countries.forEach((c) => {
let good = !![c.name, c.default_name].filter(Boolean).find(str => str.toLowerCase().indexOf(_value) !== -1)/* === 0 */;//i.test(c.name);
const names = [
c.name,
c.default_name,
c.iso2
];
names.filter(Boolean).forEach(name => {
const abbr = name.split(' ').filter(word => /\w/.test(word)).map(word => word[0]).join('');
if(abbr.length > 1) {
names.push(abbr);
}
});
let good = !!names.filter(Boolean).find(str => str.toLowerCase().indexOf(_value) !== -1)/* === 0 */;//i.test(c.name);
liMap.get(c.iso2).forEach(li => li.style.display = good ? '' : 'none');
if(good) matches.push(c);

Loading…
Cancel
Save