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

contentEditable tags #424

Closed
zbiller opened this issue Mar 17, 2020 · 2 comments · Fixed by #434
Closed

contentEditable tags #424

zbiller opened this issue Mar 17, 2020 · 2 comments · Fixed by #434
Labels
bug upstream An issue with upstream with the jquery-validation/jquery-validation library.

Comments

@zbiller
Copy link

zbiller commented Mar 17, 2020

I have a page with some fields that I complete and then submit the page to create my record.
The trick here is that I'm using a 3rd party plugin (Froala Editor) for my content field.

When submitting the form, I get this error: https://monosnap.com/file/l0ui51C1cKy4r7wKmY6FVaShalmaKs

After digging deeper into the package, I found the issue to be caused by this line of code inside the resources/assets/js/jsvalidation.js file:

if (element.name.indexOf('[') === -1 ) {

The reason this line fails, is because I'm using the Froala Editor.
If I console.log(element, element.name) this is what I get: https://monosnap.com/file/ORLerLI3AJRh4tRrLayDBlpt9ZoUGZ

As you can see, the last element is not a form input, thus it doesn't have a name attribute. Looking at the inspector, the actual form input is below: https://monosnap.com/file/nBFawaLd1rFTPttl1jB301hB73pkmi

I think the easy fix would be to just replace

if (element.name.indexOf('[') === -1 ) {

with

if (element.name !== undefined && element.name.indexOf('[') === -1 ) {

???

Also please note that with my same codebase, version 2.5 of this package, alongside Laravel 6.x worked ok.

Thanks for your support btw :) awesome package!

Environment

  • version of this package: ^3.0
  • version of Laravel: ^7.0
@bytestream
Copy link
Collaborator

Thanks for investigating this!

I actually ran into this as well (before I was added as collaborator, so it's been a bit of a mess trying to pull together all my fixes).

The issue was introduced by #409

Previously this package was using 1.14, and in 1.15 they added support for contentEditable tags, see https://github.com/jquery-validation/jquery-validation/releases

I fixed it by just disabling contentEditable tag support using:

ignore: ':hidden, [contenteditable=\'true\']'

NB: the default ignore value is :hidden (https://jqueryvalidation.org/validate/#ignore)


As far as providing a fix for this package goes... technically this is an issue upstream. There's a PR for it - jquery-validation/jquery-validation#2237 but it's concerning that the package maintainer would write this: jquery-validation/jquery-validation#2289 (comment)

I'd be more tempted to just accept a PR which disables contentEditable support given that's how this package has worked in the past.

@bytestream bytestream added bug upstream An issue with upstream with the jquery-validation/jquery-validation library. labels Mar 17, 2020
@bytestream bytestream changed the title arrayRules: reads the form inputs incorrectly contentEditable tags Mar 17, 2020
@bytestream
Copy link
Collaborator

@zbiller did you find a fix for this?

bytestream added a commit to bytestream/laravel-jsvalidation that referenced this issue Apr 19, 2020
@bytestream bytestream linked a pull request Apr 19, 2020 that will close this issue
bytestream added a commit that referenced this issue Apr 19, 2020
* Fixes #424

* Updated tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug upstream An issue with upstream with the jquery-validation/jquery-validation library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants