@fto-consult/expo-ui 8.82.8 → 8.82.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ import {StyleSheet} from "react-native";
16
16
  import {isDevEnv} from "$cplatform";
17
17
  import {isMobileMedia} from "$cplatform/dimensions";
18
18
  import APP from "$capp/instance";
19
+ import { prepareState as preparePhoneInput } from "$ecomponents/PhoneInput";
19
20
  ///la combinaison à appliquer pour modifier le contenu textuel de la valeur
20
21
  let sanitizeKeyEvent = 'ctrl+m' //le type hashtag
21
22
  import defaultKeyboardEvents from "../utils/keyboardEvents";
@@ -317,7 +318,8 @@ export default class Field extends AppComponent {
317
318
  return "Veuillez saisir une addresse email valide";
318
319
  }
319
320
  } else if(this.type ==="tel" || this.type =="phone"){
320
- if(!isValidPhoneNumber(args.displayValue || value)){
321
+ const nState = preparePhoneInput({...args,defaultValue:args.displayValue||args.value});
322
+ if(!isValidPhoneNumber(nState?.displayValue)){
321
323
  return "Merci d'entrer un numéro de téléphone valide";
322
324
  }
323
325
  } else if(((this.props.allowWhiteSpaces === false) || ((this.type ==='id' || this.type =='piece') && this.props.allowWhiteSpaces !== true))){
@@ -19,7 +19,7 @@ const asYouTypeFormatter = libPhoneNumber.AsYouTypeFormatter;
19
19
 
20
20
  // eslint-disable-next-line class-methods-use-this
21
21
  export const format = (number, iso2) => {
22
- const formatter = new asYouTypeFormatter(iso2); // eslint-disable-line new-cap
22
+ const formatter = new asYouTypeFormatter(defaultStr(iso2).toUpperCase().trim()); // eslint-disable-line new-cap
23
23
  let formatted;
24
24
  number.replace(/-/g, '')
25
25
  .replace(/ /g, '')
@@ -32,21 +32,23 @@ export const format = (number, iso2) => {
32
32
 
33
33
  return formatted;
34
34
  }
35
- const prepareState = ({defaultValue,country})=>{
36
- defaultValue = defaultStr(defaultValue);
35
+ export const prepareState = ({defaultValue,country})=>{
36
+ defaultValue = defaultStr(defaultValue).trim();
37
37
  country = defaultStr(country,appConfig.countryCode).toLowerCase();
38
- if (defaultValue) {
39
- if (defaultValue[0] !== '+') {
40
- defaultValue = `+${defaultValue}`;
38
+ country = isNonNullString(defaultValue)? PhoneNumber.getCountryCodeOfNumber(defaultValue) || country : country;
39
+ const countryData = country ? PhoneNumber.getCountryDataByCode(country) : null;
40
+ const prefix = getDialCodePrefix(countryData?.dialCode);
41
+ if (defaultValue) {
42
+ let defValue = defaultValue;
43
+ if(prefix && !defaultValue.startsWith("+") && !defaultValue.startsWith(prefix)){
44
+ defValue = prefix+defaultValue;
41
45
  }
42
- country = PhoneNumber.getCountryCodeOfNumber(defaultValue) || country;
43
- const displayValue = format(defaultValue,country);
46
+ const displayValue = format(defValue,country);
44
47
  if(displayValue){
45
48
  return {displayValue,defaultValue,country}
46
49
  }
47
- } else if(country) {
48
- const countryData = PhoneNumber.getCountryDataByCode(country);
49
- return {displayValue:countryData ? `+${countryData.dialCode}` : '',defaultValue:'',country};
50
+ } else if(prefix) {
51
+ return {displayValue:countryData ? prefix : '',defaultValue:'',country};
50
52
  }
51
53
  return {defaultValue:'',displayValue:'',country:''};
52
54
  }
@@ -85,7 +87,7 @@ export default function PhoneInputComponent(props){
85
87
  },[])
86
88
  React.useEffect(()=>{
87
89
  const nState = prepareState({defaultValue,country:country || state.country})
88
- if(nState.defaultValue !== state.defaultValue && nState.country !== state.country){
90
+ if(nState.defaultValue !== state.defaultValue && nState.country !== state.country && nState.displayValue !== state.displayValue){
89
91
  setState({...state,...nState});
90
92
  }
91
93
  },[defaultValue,country])