Reputation: 23
I have 2 js files:
I have a form with a lot of required invisible fields(these fields are needed in other pages).
When I do form.Valid(), it is validating even the invisible fields and says form is invalid even when I fill in all the data.
When I don't bundle it all works fine.
So I think the problem is with bundling those 2 files.
My question would be why is that is there something with these files we CANNOT bundle?
Any help would be appreciated.
Upvotes: 0
Views: 408
Reputation: 159
you can not bundle both together because jQuery.validate is dependant on jQuery.
so your jQuery file must load first an than jQuery.validate should load.
Upvotes: 0
Reputation: 91
I'm able to bundle these files (and others), but in one project, I have them grouped separately. In other words, I have JQuery-*.js bundled by itself, and have the Validate and other helper files in another bundle. The main reason I did it this way is because not all of my screens need the Validate portion, so it's only loaded when necessary. In another project, I bundle them together. Works in both cases.
To use the bundled files, in your Razor code, you need something like:
@Scripts.Render("~/bundles/jquery")
I would include JQuery bundle before the Validate bundle, if you use separate bundles. If using one bundle, put the validate last in the bundle list.
Upvotes: 2