You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On iOS devices, the onKeyDown event bypasses the onChange event, so we need to validate on both onKeyDown and onChange for these devices
On Android devices, number input field bypasses any restrictions to hyphens - and dots . and hence bypasses the onChange checks, for example a maximum length of 10 digits check will be bypassed, so we need global checks on onKeyDown event, which does not give access to the entire value of the input
On macOS, the behaviour is same as iOS devices
If we add a regex to either onChange or onKeyDown, then certain keys will be bypassed like BackspaceArrow KeysShiftTabCtrl + CCtrl + VEscapeTabEnter and more
API Design Approach
Approach 1
<TextFieldonChange={valdiate((e)=>{/** any component specific logic */},{specialCharacters: false,numeric: false,emojis: false,maxLength: 10})}onKeyDown={valdiate((e)=>{/** any component specific logic */},{specialCharacters: false,numeric: false,emojis: false,maxLength: 10})}/>
Approach 2
<TextField{...validate({specialCharacters: false,numeric: false,emojis: false,maxLength: 10},{onChange: (e)=>{/** any component specific logic */},onKeyDown: (e)=>{/** any component specific logic */}})}/>
API development approach
typeOptions=Partial<{specialCharacters: boolean;numeric: boolean;emojis: boolean;maxLength: number;}>;functionvalidate(options: Options,props?: TextFieldProps): TextFieldProps{constspecialCharacters="`~!@#$%^&*()_+-={}|[]\\:\"';<>?,./".split();constnumbers="0123456789".split();constalphabets="abcdefghijklmnopqrstuvwxyz".split();constalphabetsCapitalized=alphabets.map((char)=>char.toUpperCase()).split();return{onChange: (e)=>{if(options.specialCharacters&&specialCharacters.some((char)=>e.target.value.includes(char))){returne.preventDefault();}if(options.numbers&&numbers.some((char)=>e.target.value.includes(char))){returne.preventDefault();}// rest of the validationsprops.onChange?.(e);},onKeyDown: (e)=>{// similar to onChange, but e.target.value is not available, so do maxLength check accordingly}}}
Test Cases
Test cases should be written thoroughly and ran across multiple platform
The text was updated successfully, but these errors were encountered:
Problem statement
-
and dots.
and hence bypasses the onChange checks, for example a maximum length of 10 digits check will be bypassed, so we need global checks on onKeyDown event, which does not give access to the entire value of the inputBackspace
Arrow Keys
Shift
Tab
Ctrl + C
Ctrl + V
Escape
Tab
Enter
and moreAPI Design Approach
Approach 1
Approach 2
API development approach
Test Cases
Test cases should be written thoroughly and ran across multiple platform
The text was updated successfully, but these errors were encountered: