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

ADD: Client-side Sign Up form validation #7086

Merged
merged 4 commits into from
Jan 4, 2020
Merged

ADD: Client-side Sign Up form validation #7086

merged 4 commits into from
Jan 4, 2020

Conversation

VladimirMikulic
Copy link
Contributor

@VladimirMikulic VladimirMikulic commented Jan 2, 2020

Changes:

  • Removed realtime_usernmae_validation.js
  • CSS classes for valid and invalid input elements
  • Minor changes in _create_form.html.erb

The old sign up form would only validate a username.
This change provides a nice UI to the user while filling the form.

Demo

Resolves #3439 & #4268

@SidharthBansal
Copy link
Member

Please add comments. Thanks for working on it

@codecov
Copy link

codecov bot commented Jan 2, 2020

Codecov Report

Merging #7086 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7086   +/-   ##
=======================================
  Coverage   80.81%   80.81%           
=======================================
  Files          97       97           
  Lines        5567     5567           
=======================================
  Hits         4499     4499           
  Misses       1068     1068

@VladimirMikulic
Copy link
Contributor Author

Thank you @SidharthBansal. I've added the comments for most 'complicated' functions.
Code is pretty declarative, so there shouldn't be any issues with the rest.

@SidharthBansal
Copy link
Member

SidharthBansal commented Jan 2, 2020 via email

@SidharthBansal
Copy link
Member

SidharthBansal commented Jan 2, 2020

Does this pr handles both sign up form and sign up modal? OR do we need two separate prs for that?

app/assets/javascripts/validation.js Outdated Show resolved Hide resolved
app/assets/javascripts/validation.js Show resolved Hide resolved
@VladimirMikulic
Copy link
Contributor Author

@SidharthBansal the PR handles both 😄

@SidharthBansal
Copy link
Member

Can you please resolve code climate?

Copy link
Member

@SidharthBansal SidharthBansal left a comment

Choose a reason for hiding this comment

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

Lgtm

@SidharthBansal
Copy link
Member

I will request Jeff or cess to review once more as changes are huge and merge it
@jywarren @cesswairimu

@VladimirMikulic
Copy link
Contributor Author

Yeah, changes are huge 😄

Copy link
Member

@SidharthBansal SidharthBansal left a comment

Choose a reason for hiding this comment

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

Few things remaining

@SidharthBansal
Copy link
Member

SidharthBansal commented Jan 3, 2020 via email

@VladimirMikulic
Copy link
Contributor Author

@SidharthBansal I implemented the changes that you've requested.
The issue with code CodeClimate can not be fixed, it's the way that JS works.
CodeClimate sees SignUpFormValidator as a function, but it is a class(JS way).

Copy link
Member

@SidharthBansal SidharthBansal left a comment

Choose a reason for hiding this comment

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

Can we make separate files like real time username validation for password too?
I think we should keep the logics separate.
We should do things in modular fashion. What do you think?

@SidharthBansal
Copy link
Member

SidharthBansal commented Jan 3, 2020

Ignore codeclimate then


function validateEmail(obj) {
var email = this.value;
var regexp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
Copy link
Member

Choose a reason for hiding this comment

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

Try to use explicit variable names like emailRegex. I can't understand which regex are you talking about if I am new developer. I hope you understand. Do similarly at other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

Please ensure that the regex used here and at the backend are SAME.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am unable to find the email regex in RoR. Maybe it's not there? Some functionality is not in this repo, but in a "database-backed something" as @jywarren described it.

Copy link
Member

Choose a reason for hiding this comment

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

Hi! I hope to catch up on this PR today, but need to go eat some lunch first! For now i hope this helps: the regex is generally in the Authlogic Ruby gem, but we've overridden it here:

Authlogic::Regex::LOGIN = /\A[A-Za-z\d_\-]*\z/

I actually am not sure why we did that. But we did. :-)

We could look back in the history to see what the justification was, but it seems out of scope for this use case. Let's just be sure people seeing that line can find their way to the JS code, and vice versa, so that if either one is ever changed, the developer knows to change the corresponding one. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This the username validation regex, but I need a regex that validates the email address.
It's simply not there :(

@VladimirMikulic
Copy link
Contributor Author

VladimirMikulic commented Jan 3, 2020

@SidharthBansal it is already modular. Making separate files wouldn't make sense.
It's just a simple form.

@SidharthBansal
Copy link
Member

SidharthBansal commented Jan 3, 2020 via email

@jywarren
Copy link
Member

jywarren commented Jan 3, 2020

I think the broader issue of JS maintainability in plots2 is a really critical one. Over the past few years we've spun out quite a few critical JS systems into internally-tested independent modules/libraries, as described in https://publiclab.org/notes/warren/05-22-2019/draft-of-a-public-lab-software-roadmap-comments-welcome -- this includes:

etc etc!

However, the code remaining is not well organized and, while this would be out of the scope of this PR, a bigger project to organize and properly test smaller bits of JS within the app seems very worthwhile. Just don't let it distract too much from the narrower issue at stake here. Let's make good pragmatic decisions here and just leave things a little better than they were.

As to maintainability of this code, one thing i strongly recommend is to write a system test (such as in /test/system/) to demonstrate this working. That'll ensure it doesn't get broken by future coders, and will be a backstop protection if we do a bigger JS refactor in the future. If our JS were really thoroughly tested, we would not be as hesitant to tear out a lot and refactor it!

Thanks, all, for your hard work!

@jywarren
Copy link
Member

jywarren commented Jan 3, 2020

And, just to share my thinking - client-side validation is really nice, but it does affect a critical system -- login -- and so the stakes are very high. We want to be sure this is well protected with tests. And, that it remains maintainable and readable, and doesn't create undue maintenance burden in the future. Those are the metrics I keep in mind when reviewing code that affects this area of functionality!

@VladimirMikulic
Copy link
Contributor Author

@SidharthBansal @jywarren what should be my next step?

@VladimirMikulic
Copy link
Contributor Author

Also @jywarren this would need JS test, we can't write Ruby to test this because we manipulate the DOM and we need to access it via JS to be able to verify that form is displaying errors.

@jywarren
Copy link
Member

jywarren commented Jan 3, 2020 via email

@VladimirMikulic
Copy link
Contributor Author

@SidharthBansal @jywarren I've added the test.

Screenshot_20200103_231811

@jywarren
Copy link
Member

jywarren commented Jan 3, 2020

OK, pending #7106 we should be able to merge this too! We're going to lower the thresholds for both project and patch and this should pass then. Thanks for your patience!!

@VladimirMikulic
Copy link
Contributor Author

@jywarren no problem, thank you :)

Copy link
Member

@SidharthBansal SidharthBansal left a comment

Choose a reason for hiding this comment

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

Lgtm

@SidharthBansal
Copy link
Member

Thanks all for working on thid

@jywarren
Copy link
Member

jywarren commented Jan 4, 2020

OK, with #7106 merged, I /believe/ we should be able to get this to pass by rebasing it! Can you give a try? Thank you!

Changes:
 - Removed realtime_usernmae_validation.js
 - CSS classes for valid and invalid input element
 - Minor changes in _create_form.html.erb

The old sign up form would only validate a username.
This change provides a nice UI to the user while filling the form.

Resolves #3439
Changes:
 - Comments for most important functions in form validation
 - Refactor isPasswordValid to be pure function(no UI updates)
@VladimirMikulic
Copy link
Contributor Author

@jywarren done!

@jywarren
Copy link
Member

jywarren commented Jan 4, 2020

Awesome, fingers 🤞

@jywarren jywarren merged commit 552bf76 into publiclab:master Jan 4, 2020
@jywarren
Copy link
Member

jywarren commented Jan 4, 2020

Awesome!!!

@VladimirMikulic
Copy link
Contributor Author

Wohoo 🚀

@jywarren
Copy link
Member

jywarren commented Jan 4, 2020 via email

@VladimirMikulic
Copy link
Contributor Author

Hi @jywarren. I've tested the form and noticed a bug. It's nothing serious though, only 5 lines changed.

@jywarren
Copy link
Member

jywarren commented Jan 5, 2020 via email

@VladimirMikulic
Copy link
Contributor Author

@jywarren I'll add the test for this 👍

@SidharthBansal SidharthBansal added this to the Login/SignUp & OAuth milestone Jan 7, 2020
Tlazypanda pushed a commit to Tlazypanda/plots2 that referenced this pull request Jan 14, 2020
* ADD: Client-side Sign Up form validation

Changes:
 - Removed realtime_usernmae_validation.js
 - CSS classes for valid and invalid input element
 - Minor changes in _create_form.html.erb

The old sign up form would only validate a username.
This change provides a nice UI to the user while filling the form.

Resolves publiclab#3439

* ADD: Comments for SignUp form validation

Changes:
 - Comments for most important functions in form validation
 - Refactor isPasswordValid to be pure function(no UI updates)

* ADD: Support for pl.org/register form validation

* ADD: Tests for signup modal form validation
vinitshahdeo pushed a commit to vinitshahdeo/plots2 that referenced this pull request Feb 1, 2020
* ADD: Client-side Sign Up form validation

Changes:
 - Removed realtime_usernmae_validation.js
 - CSS classes for valid and invalid input element
 - Minor changes in _create_form.html.erb

The old sign up form would only validate a username.
This change provides a nice UI to the user while filling the form.

Resolves publiclab#3439

* ADD: Comments for SignUp form validation

Changes:
 - Comments for most important functions in form validation
 - Refactor isPasswordValid to be pure function(no UI updates)

* ADD: Support for pl.org/register form validation

* ADD: Tests for signup modal form validation
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.

Success sign when Password match with Confirmation password
4 participants