-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix Validated Components #340
Conversation
…validation function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like where the code is moving, but i dont understand how the chaining of validation handles.
@@ -110,9 +111,9 @@ const ConfirmationContents: FunctionComponent<{ | |||
returnValue?: any | |||
onConfirm: (returnValue?: any) => void | |||
confirmationLabel: string | |||
testID?: string | |||
testID: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😲
}, | ||
ref | ||
) => { | ||
const [errorMessage, setErrorMessage] = useState('') | ||
const errorMessage = validationFunc(color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be more of a validateHexCode(color) && validationFunc(color)
relationship? so that validating that a color matches a palette map somewhere doesnt mean you have to rewrite validateHexCode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made validationFunc
to be validateHexCode
by default, but in case we ever want to support rgb values or named colors a different validation function can be passed in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
setErrorMessage(newErrorMessage) | ||
onChange(cleanedValue, inputStatus) | ||
onChange(e.target.value, inputStatus) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why no more input cleaning here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose I could trim out space characters at the very least
@drdelambre can you clarify "Chaining of validation"? |
like.. whats the difference between a text input, color hex input, and a "only shades of grey" input? is the thinking that the last input is going to be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offlined the conversation and we're aiming for max flexibility
Closes #339
Turns out the bug was caused by the hexcode validator function always returning a string when it was expecting a
null
value to determine if is valid, hence it always returning invalidChanges
FormValidationElement
to expectstring
instead ofany
ColorPicker
andFormValidationElement
ValidationFunction
to enforce consistency across these components (and potentially more)validationFunc
prop toColorPicker
Checklist
Check all that apply