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

Only one live error message shows at a time, for validation on sign-up page #12

Closed
tracey-le opened this issue Jan 21, 2017 · 13 comments
Closed
Assignees
Labels

Comments

@tracey-le
Copy link
Collaborator

tracey-le commented Jan 21, 2017

Example: If you type a username that's too short, you get an error message as soon as you leave the field. Then if you move onto the nickname field and type a nickname that's too short and lose focus on the field, you get an error message for the nickname too.

Expected behaviour: both error messages should stay since they're relevant still.
What happens: the error message for the username disappears while the error message for nickname is still there.

I think it has something to do with when we make .text('error message etc ') appear in the <p>'s with class="error" — I don't know if it affects <p>'s that have already had their text changed or if it makes them blank.

Here is part of the code for the username field:

screen shot 2017-01-21 at 10 16 57 pm

screen shot 2017-01-21 at 10 21 48 pm

Also I don't think having this repeated at the start of every blur event is a good idea hehe, it also might be affecting things:

var $form = $('form.sign-in');
    $('.error').html("");

I'm not quite sure what the second line does 😊 does it find a new tag with class="error" each time? Anyway, just recording some ideas :)

@tracey-le
Copy link
Collaborator Author

tracey-le commented Jan 21, 2017

Oh, or does $('.error').html("") make all the tags with class=error have blank text? 😮🤔 I'll look into it ☺️😄

@tracey-le
Copy link
Collaborator Author

tracey-le commented Jan 21, 2017

Okay, just tested replacing the empty string in $('.error').html("") with something random — like $('.error').html("food") — and it did change all the error texts to food :)

@tracey-le
Copy link
Collaborator Author

tracey-le commented Jan 21, 2017

(Going to leave this for now, feel free to take a look 😃)

@lyneca lyneca added the bug label Jan 21, 2017
@tracey-le
Copy link
Collaborator Author

Thanks @lyneca 👍

@tracey-le tracey-le self-assigned this Jan 21, 2017
@lyneca
Copy link
Collaborator

lyneca commented Jan 21, 2017

Calls to .find() can return more than one object

@lyneca
Copy link
Collaborator

lyneca commented Jan 21, 2017

I don't know much about the code, but does $input.parent().find() contain just the element you want to change, or both error fields?

@tracey-le
Copy link
Collaborator Author

Ooh thank you about .find() 😄

I think so far it's been only one error field at a time that changes so it looks like $input.parent().find() just contains one field from what I can see...? but I'm not too sure. I'll take a look tomorrow 👍

@tracey-le
Copy link
Collaborator Author

I have an idea for this, working on it now 😃

@tracey-le tracey-le changed the title Only one live error message on sign-up page shows at a time Only one live error message on sign-up page shows at a time, for signup page Jan 21, 2017
@tracey-le tracey-le changed the title Only one live error message on sign-up page shows at a time, for signup page Only one live error message shows at a time, for validation on sign-up page Jan 21, 2017
tracey-le added a commit that referenced this issue Jan 21, 2017
Removed the repeated lines that were setting all tags with
`class=error` to have blank text each time a blur event was triggered.

Then added lines to set the tags with `class=error` to have blank text
if the field was valid, in each of the validation funcs.

#12
@tracey-le
Copy link
Collaborator Author

tracey-le commented Jan 21, 2017

Okay, I think the fix seems to be working for now at least 😃

Multiple live validation error messages:
screen shot 2017-01-22 at 9 18 40 am

@tracey-le
Copy link
Collaborator Author

lyneca:
I don't know much about the code, but does $input.parent().find() contain just the element you want to change, or both error fields?

t1-tracey:
I think so far it's been only one error field at a time that changes so it looks like $input.parent().find() just contains one field from what I can see...? but I'm not too sure. I'll take a look tomorrow 👍

I'm just gonna take a look at this that Luke said earlier 😃

@tracey-le
Copy link
Collaborator Author

Hmm it seems just to get one parent element? 🤔 I just had a quick check here https://api.jquery.com/parent/

@tracey-le
Copy link
Collaborator Author

Oh, okay I see that .find() looks for descendants 😮 https://api.jquery.com/find/

@tracey-le
Copy link
Collaborator Author

tracey-le commented Jan 21, 2017

The hierarchy for the signup page is like this:

screen shot 2017-01-22 at 9 48 18 am

So from the jQuery API, it looks like that this —

screen shot 2017-01-22 at 9 49 36 am

gets the parent of the input element that's stored in the $input var, which will be a <div>. Then it looks for descendants of the <div> that are of class error, which will be the <p>. And its text will be set to whatever.

I didn't know that before 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants