colinaut / alpinejs-plugin-simple-validate

Simple Alpine form validation plugin
97 stars 4 forks source link

Using plugin with webpack fails #1

Closed Rocketpilot closed 2 years ago

Rocketpilot commented 2 years ago

Running this plugin inside a Symfony 5.4 application on localhost with Webpack Encore.

Using the recommended config, the plugin clobbers all Alpine JS code on the page, and returns the following error in the browser console:

"ReferenceError: Can't find variable: data" inside getData -- alpine.validate.esm.js:31

Running Alpine and the plugin through a CDN script link works fine.

I've run @ryangjchandler/alpine-tooltip through Encore without issue and pure AlpineJS works too.

Browser console error takes me to this specific line:

} else if (format === dateFormats[1] && /^(\d{1,2})[-\/.](\d{1,2})[-\/.](\d{4})$/.test(str)) {

colinaut commented 2 years ago

Thanks! Discovered a dumb error (I didn't use let/const to declare the data variable in getData which I'm guessing Webpack was tripping over. I just updated it. I am not running your setup so please let me know if this fixes the issue.

Rocketpilot commented 2 years ago

Gotta say this is the best support I've ever had on Github, thank you so much.

colinaut commented 2 years ago

You're welcome! I happened to be messing around with the plugin right when you sent the issue so I dove in to fix it.

Thanks for pointing out the bug!

Rocketpilot commented 2 years ago

Great! I might have a few more ideas now that I've actually got it working...