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

getErrorLocation #46

Closed
awgul opened this issue Aug 10, 2019 · 7 comments
Closed

getErrorLocation #46

awgul opened this issue Aug 10, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@awgul
Copy link

awgul commented Aug 10, 2019

Hey,

This code here is problematic.
Why?
What if a field doesn't have a sibling?
I have just one field in a container and that's all and so because of that I get error because there is no sibling.

      // If the message should come after the field
      if (settings.messageAfterField) {
        return target.nextSibling;
      }

and than you use
field.parentNode.insertBefore(error, location);

and it should be like selecting insertBefore or insertAfter

Best,
Tom

@awgul
Copy link
Author

awgul commented Aug 10, 2019

Sorry, but there is no insertAfter :)
But I hope you understand what I mean here.
So if there is no sibling we could use append and in this case it would be like insertAfter because there is only one element.

@awgul
Copy link
Author

awgul commented Aug 10, 2019

Now when there is no sibling and i want to messageAfterField=true I get error
Cannot read property 'parentNode' of null, because no sibling.

@cferdinandi
Copy link
Owner

Please provide a reduced test case.

@awgul
Copy link
Author

awgul commented Aug 10, 2019

Hey,

Have a look:
https://codepen.io/tawg/pen/MNPpLw

It doesn't create an error if there is some sibling, it works fine when there is a text node.
But in this case there is no white space after the input field.

@cferdinandi
Copy link
Owner

Nice find! I need to create an empty text node after the element if there isn't a sibling, it would seem.

I'll add this to getErrorLocation() (tested and it works)

// If the message should come after the field
if (settings.messageAfterField) {

	// If there's no next sibling, create one
	if (!target.nextSibling) {
		target.parentNode.appendChild(document.createTextNode(''));
	}

	return target.nextSibling;
	
}

@cferdinandi cferdinandi added the bug Something isn't working label Aug 13, 2019
@cferdinandi
Copy link
Owner

Fixed in v1.4.6

@awgul
Copy link
Author

awgul commented Aug 21, 2019

Great, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants