proengsoft/laravel-jsvalidation

Uncaught TypeError: Cannot read property 'element' of undefined

namik-mesic opened this issue · 4 comments

Subject of the issue

Having a problem with validating fields of type select when there is an exists rule querying the database.

Your environment

JSvalidation v4.4.1
Laravel v8.17.2

Additional info:
mysql database, standard laravel setup no fancy stuff

Steps to reproduce

  • Create a select input and populate with values (in my case the option values were ids for a fk).
  • Render validation js in view

Add similar rule for request:
'parent_id' => 'nullable|exists:collections,id'

Perhaps I should note that the parent_id is a fk to the same table (collections).
The validation works in all cases except when there is an exists rule.
There are other rules in the request as well (I could remove all of them and it still failed).
Obviously, when I removed the exists rule everything works.

Expected behaviour

The validation should either pass or fail (in my case it should have passed because the given id did exist in the collections table).

Actual behaviour

Browser scrolls to field, without adding error / success classes for validation and stores the input anyway.
Window does not continue with normal form submit.

Please could you setup a minimal GitHub repo which replicates the issue. There's no known issues with exists rules or validation

At the moment it's quite difficult for me to pinpoint when this happens with certainty.
I just checked a few other requests which use the exists rule (forgot about testing them beforehand) and noticed that they were working fine.

The only occurrence I can confirm that happened to me is when the exists is tied to the same table the table of the validating entry is (in original case collections).

I am sorry but I am unable to boot up a repo for this at the moment.
Would a few screenshots help? :)

It sounds like it might just be an issue with the display of the error. You can change it by creating your own view 'view' => 'jsvalidation::bootstrap', in the config file

I apologize,

The entire issue was caused by the fact I used the wrong request class in the controller method.
Everything works fine now.

Sorry for causing distress!

Best,

Namik