ajaxWithForm Uncaught ReferenceError: _ is not defined
dragonfly4 opened this issue · 2 comments
dragonfly4 commented
Summary of problem
Upgrade Laravel v9 to v10.
Datatable with custom select returns fatal error.
Reference issue yajra/laravel-datatables#2707
Code snippet of problem
return $this->builder()
->setTableId('mystuff-table')
->columns($this->getColumns())
->ajaxWithForm('/mycustomurl', '#mystuff-table-form')
Uncaught ReferenceError: _ is not defined
delete data.search.regex;var formData = _.groupBy($("#mystuff-table-form").find("input, select, textarea").serializeArray(), function(d) { return d.name; } );
System details
- Operating System: Rocky Linux 9
- PHP Version: 8.1.22
- Laravel Version: 10
- Laravel-DataTables Version: 10.8.0
- Laravel-DataTables-html Version: 10.8.1
- jQuery 3.7.0
Solution
Since I upgraded everything together I was not sure if the problem was in my code or in the package. Lost a full day with this so sharing it here to help other people.
Include the underscore package and the error is gone. Custom filter is working again.
<script src="https://cdn.jsdelivr.net/npm/underscore@1.13.6/underscore-umd-min.js"></script>
yajra commented
Oh, sorry about that. Didn't notice that the new script requires lodash
since it's mostly a default in every Laravel app.
Glad you sorted this out and thanks for sharing your solution.
dragonfly4 commented
@yajra I am using lodash in my project.
"lodash": "^4.17.21",
I'm not a JS expert. Maybe underscore function has been removed from the package?