forked from MapComplete/MapComplete
		
	Fix: fix validation of question input; remove some obsolete logging; stabilize output of generate:translations wrt newlines
This commit is contained in:
		
							parent
							
								
									755f905c36
								
							
						
					
					
						commit
						1f39ba9ab5
					
				
					 26 changed files with 7328 additions and 71 deletions
				
			
		|  | @ -1,7 +1,8 @@ | |||
| import { Translation } from "../../i18n/Translation.js" | ||||
| import {Translation} from "../../i18n/Translation.js" | ||||
| import Translations from "../../i18n/Translations.js" | ||||
| import * as emailValidatorLibrary from "email-validator" | ||||
| import { Validator } from "../Validator" | ||||
| import {Validator} from "../Validator" | ||||
| 
 | ||||
| export default class EmailValidator extends Validator { | ||||
|     constructor() { | ||||
|         super("email", "An email adress", "email") | ||||
|  |  | |||
|  | @ -1,12 +1,28 @@ | |||
| import { parsePhoneNumberFromString } from "libphonenumber-js" | ||||
| import { Validator } from "../Validator" | ||||
| import {parsePhoneNumberFromString} from "libphonenumber-js" | ||||
| import {Validator} from "../Validator" | ||||
| import {Translation} from "../../i18n/Translation"; | ||||
| import Translations from "../../i18n/Translations"; | ||||
| 
 | ||||
| export default class PhoneValidator extends Validator { | ||||
|     constructor() { | ||||
|         super("phone", "A phone number", "tel") | ||||
|     } | ||||
| 
 | ||||
|     isValid(str, country: () => string): boolean { | ||||
| 
 | ||||
|     getFeedback(s: string, requestCountry?: () => string): Translation { | ||||
|         const tr = Translations.t.validation.phone | ||||
|         const generic = tr.feedback | ||||
|         if(requestCountry){ | ||||
|         const country = requestCountry() | ||||
|             if(country){ | ||||
|                 return  tr.feedbackCountry.Subs({country}) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return generic | ||||
|     } | ||||
| 
 | ||||
|     public isValid(str, country: () => string): boolean { | ||||
|         if (str === undefined) { | ||||
|             return false | ||||
|         } | ||||
|  | @ -20,13 +36,17 @@ export default class PhoneValidator extends Validator { | |||
|         return parsePhoneNumberFromString(str, countryCode)?.isValid() ?? false | ||||
|     } | ||||
| 
 | ||||
|     reformat = (str, country: () => string) => { | ||||
|     public reformat(str, country: () => string) { | ||||
|         if (str.startsWith("tel:")) { | ||||
|             str = str.substring("tel:".length) | ||||
|         } | ||||
|         let countryCode = undefined | ||||
|         if(country){ | ||||
|             countryCode = country() | ||||
|         } | ||||
|         return parsePhoneNumberFromString( | ||||
|             str, | ||||
|             country()?.toUpperCase() as any | ||||
|             countryCode?.toUpperCase() as any | ||||
|         )?.formatInternational() | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue