BlueM / form-change-tracker

Tracks pristine/dirty state of in-browser form controls
2 stars 0 forks source link

Should This Work With Laravel Mix? #1

Open dbarou55e opened 6 years ago

dbarou55e commented 6 years ago

I've been trying to use this library in a Laravel application, but I can't seem to get it to work. I've included it in my main app.js file via NPM, but I get the following error when invoking an instance:

Uncaught ReferenceError: FormChangeTracker is not defined

I can open my app.js file and see that the code is in there.

Any thoughts??

BlueM commented 6 years ago

Laravel Mix is a wrapper around Webpack, so this is supposed to work – but as I don’t use Laravel, I cannot tell you how.

The question is: how did you include it in your app.js? Which is the exact code? My guess is that you do not have this line in your application's JS code:

const FormChangeTracker = require('form-change-tracker');

If you have this line, it should work with Webpack – and I’d assume it should then also work with Laravel Mix.

dbarou55e commented 6 years ago

Thank you for your reply. Unfortunately, I have not been able to get this to work with Laravel Mix/Webpack. Here is what I did:

  1. npm i form-change-tracker

  2. In app.js I put, const FormChangeTracker = require('form-change-tracker');

  3. npm run dev

  4. In my "view" I simply added: new FormChangeTracker();

  5. I get the following error: Uncaught ReferenceError: FormChangeTracker is not defined

The FormChangeTracker code is definitely in my app.js file.

My main reason for wanting to use this is because you said it is supported in iOS (which doesn't support beforeunload). I hope I can get it to work.

BlueM commented 6 years ago

Then I’m afraid I can’t help you, as I don’t have any experience with Mix. It looks like the issue is how Laravel handles the JS code in the view, but this is only a guess.

Regarding your comment on iOS support: the library does not provide anything beyond input/control observering and state tracking (regardless of whether on a desktop browser or Mobile Safari), so I’m not sure it would solve your problem with beforeunload.