Feat:Email validation regex field added along with default values#820
Feat:Email validation regex field added along with default values#820notsidney merged 12 commits intorowyio:developfrom
Conversation
Signed-off-by: Raj Gaurav Maurya <rajgmsocial19@gmail.com>
|
This PR only adds the text field to save the custom regex to the column config. Edit: we have exiting behavior that validates any field if it has the |
Signed-off-by: Raj Gaurav Maurya <rajgmsocial19@gmail.com>
|
@RajGM is attempting to deploy a commit to the Rowy Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @notsidney |
|
Thanks, it works when I manually update the regex (such as adding a space at the end) then saving. The issue is that having that as the default value in the UI implies that that setting has already been set and that clicking “Update” will set it. However, reading the code, it’s only set when there is an input to the text field, so it has to be typed in first. I don’t think it’s a good idea to have it as the default value, but rather have a button next to it that says “Use standard regex” or something similar that sets the regex. This makes sure the user doesn’t think the regex is set but it’s not working. |
Signed-off-by: Raj Gaurav Maurya <rajgmsocial19@gmail.com>
notsidney
left a comment
There was a problem hiding this comment.
Please commit the suggestions, then this PR is ready to be merged.
| const emailFieldValidation = useRef<HTMLInputElement>(null); | ||
| const useStandardRegex = () => { | ||
| if (emailFieldValidation.current != null) { | ||
| emailFieldValidation.current.value = "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$"; |
There was a problem hiding this comment.
| emailFieldValidation.current.value = "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$"; | |
| onChange("validationRegex")("^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$"); |
As I wrote in a previous comment:
it works when I manually update the regex (such as adding a space at the end) then saving.
it’s only set when there is an input to the text field, so it has to be typed in first.
This is because you call onChange when the user types in the text field only. You manually change the value of the input element in the DOM, which doesn’t update the React state.
So when the user clicks the button, it updates the rendered input but doesn’t save in the column config, so it will never validate unless if they type in the input after clicking the button.
|
|
||
| export default function Settings({ onChange, config }: ISettingsProps) { | ||
|
|
||
| const emailFieldValidation = useRef<HTMLInputElement>(null); |
There was a problem hiding this comment.
| const emailFieldValidation = useRef<HTMLInputElement>(null); |
Remove unnecessary refs.
| return ( | ||
| <> | ||
| <TextField | ||
| inputRef={emailFieldValidation} |
There was a problem hiding this comment.
| inputRef={emailFieldValidation} |
Remove unnecessary refs.
Signed-off-by: Raj Gaurav Maurya <rajgmsocial19@gmail.com>
…nto emailValidation_799
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
|
Hi @notsidney |
|
@RajGM What’s the benefit of copying to the clipboard instead of updating the value in state directly? The user would have to click the button then click on the text field then paste. I already provided a working suggestion that would have resolved this issue. |
|
Ok, let me directly implement the changes into state using https://www.npmjs.com/package/jotai |
notsidney
left a comment
There was a problem hiding this comment.
No, it is entirely unnecessary to have to use Jotai. The suggestion I made previously is enough to implement this behavior. Let’s get this PR over the line.
| export default function Settings({ onChange, config }: ISettingsProps) { | ||
|
|
||
| const copyStandardRegex = () => { | ||
| navigator.clipboard.writeText('^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$'); |
There was a problem hiding this comment.
| navigator.clipboard.writeText('^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$'); | |
| onChange("validationRegex")("^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$"); |
As I wrote in a previous comment:
it works when I manually update the regex (such as adding a space at the end) then saving.
it’s only set when there is an input to the text field, so it has to be typed in first.
This is because you call
onChangewhen the user types in the text field only. You manually change the value of the input element in the DOM, which doesn’t update the React state.So when the user clicks the button, it updates the rendered input but doesn’t save in the column config, so it will never validate unless if they type in the input after clicking the button.
There was a problem hiding this comment.
Hi Sidney
Can you please refer to some docs or something.
While I understood what you are trying to convey but being unable to implement the feature.
There was a problem hiding this comment.
I’ve gone ahead and merged this PR with some changes to make it work. An updated contribution guide will be published shortly, which will help for more complex contributions. Here’s a draft link.
For this feature:
- The
Settingscomponent takesonChangeandconfigas props.configis the current local state of the column config.onChangewill update the config in local state. - A parent component renders this
Settingscomponent and an “Update” button that will save the updated config stored in local state to the database. - Separately, the
TextFieldcomponent has its ownonChangeprop, where you can pass a function that will be called whenever the user types in that text field. - You set this to update the local state using
onChangefromSettings. So the user can type their own regex and it will be saved when they click “Update”. - When you created the “Use standard Regex” button, you did not use
onChangefromSettings, but rather changed the rendered input directly (using a ref). This means you did not “inform” React, so the local state did not change.- You can learn more about this in the React docs. We use controlled components but you treated it like an uncontrolled component. The source of truth is in the local state (in the parent component).
- When the user clicks “Update”, the parent component saves the local state. But since it was never updated, the standard regex is never saved to the database, so there is no validation.
The way to fix it is to use the onChange prop from Settings for the button, which you already did for the TextField.

Signed-off-by: Raj Gaurav Maurya rajgmsocial19@gmail.com