Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device Alias form has 3 validation factors: #813

Merged
merged 9 commits into from
Aug 23, 2022
Merged

Conversation

wackyleo459
Copy link
Contributor

  • Max length of 30 characters
  • Name can not start with a space
  • Name should not contain special characters (only alphanumeric characters, underscore character, and hyphen or space in the middle are allowed)

- Max length of 30 characters
- Name can not start with a space
- Name should not contain special characters (only alphanumeric characters, underscore character, and hyphen or space in the middle are allowed)
@wackyleo459 wackyleo459 changed the title Device Alias form validation has 3 validation factors: Device Alias form has 3 validation factors: Aug 17, 2022
Copy link
Collaborator

@nmattia nmattia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm not entirely sure how custom validity works. Do the maxlength and pattern cause the input to become red as well? If the pattern isn't matched (e.g. if I write "###") what will the user see?

const firstChar = deviceInput.value[0];
const lastChar = deviceInput.value.slice(-1);

if (firstChar === " ") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pattern above (^[A-Za-z0-9_]+((-|\\s)*[A-Za-z0-9_])*$) already seems to preclude starting with a space; which validity check takes precedence here? Same question below with the checks below.

Copy link
Contributor Author

@wackyleo459 wackyleo459 Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmattia I've made the changes. Spellcheck option changed to false (this was why you were seeing red underline). Maxlength prevents user from typing beyond 30 characters.

Error message will show in this order of precedence:

  1. If no entries (validity.valueMissing)

Following all fall under validity.patternMismatch

  1. If name starts with space
  2. If it ends with space or hyphen
  3. If there are special characters

NOTE: There was another page (Create a new Internet Identity Anchor) that had the exact same form. The logic is added there as well. Please review.

Screen.Recording.2022-08-18.at.3.02.37.PM.mov

@wackyleo459 wackyleo459 enabled auto-merge (squash) August 18, 2022 22:16
Copy link
Collaborator

@nmattia nmattia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Tried it out locally, works great.

As expected, clicking the submit button doesn't take me to the next page when the validity check is failing. I'm guessing this is form behavior; what would happen if we used .onclick instead of .onsubmit? Is this something we need to worry about?

- Device Alias Form input: name can't start or end with an underscore but can be in the middle
@wackyleo459
Copy link
Contributor Author

Thanks a lot! Tried it out locally, works great.

As expected, clicking the submit button doesn't take me to the next page when the validity check is failing. I'm guessing this is form behavior; what would happen if we used .onclick instead of .onsubmit? Is this something we need to worry about?

We don't need to worry about this. Even if the .onclick gets triggered, the parent form will not allow it to be submitted if validation fails. I tried to simulate the behavior (with mouse click and the console) and will not work.

I've extracted the function, so it looks cleaner.

Copy link
Collaborator

@nmattia nmattia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

@wackyleo459 wackyleo459 merged commit 707142a into main Aug 23, 2022
@wackyleo459 wackyleo459 deleted the sueann/formValidation branch August 23, 2022 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants