components/jqueryui
Laravel wrapper for jQuery UI components and assets. Provides easy installation and integration of widgets, themes, and related front-end resources into your app, helping you add UI interactions like datepickers, dialogs, and autocompletes with minimal setup.
Installation
Add the package via Composer (if available) or include via CDN in your resources/views/layouts/app.blade.php:
<!-- Option 1: CDN (Recommended for quick start) -->
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<!-- Option 2: Local (if packaged) -->
<link href="{{ asset('vendor/jqueryui/jquery-ui.css') }}" rel="stylesheet">
<script src="{{ asset('vendor/jqueryui/jquery-ui.min.js') }}"></script>
First Use Case Initialize a basic autocomplete widget in a Blade template:
<input id="search-input">
<script>
$(function() {
$("#search-input").autocomplete({
source: ["Option 1", "Option 2", "Option 3"]
});
});
</script>
Laravel Integration Publish assets (if packaged) and compile via Laravel Mix:
npm install jquery-ui-dist
Update webpack.mix.js:
mix.copy('node_modules/jquery-ui-dist/jquery-ui.css', 'public/css');
mix.copy('node_modules/jquery-ui-dist/jquery-ui.min.js', 'public/js');
Dynamic Data Binding Fetch remote data for widgets (e.g., autocomplete) via Laravel routes:
$("#search-input").autocomplete({
source: function(request, response) {
$.getJSON("{{ route('search.autocomplete') }}", {
term: request.term
}, response);
}
});
Form Validation Use jQuery UI dialogs for custom validation feedback:
$('form').validate({
errorPlacement: function(error, element) {
if (element.attr("name") === "email") {
$("#dialog").dialog("open");
} else {
error.insertAfter(element);
}
}
});
Laravel Blade Integration Pass widget options dynamically:
<input id="user-search" data-options='@json($widgetOptions)'>
<script>
$("#user-search").autocomplete($("#user-search").data("options"));
</script>
@if).resources/sass/ and compile with Laravel Mix.// In a controller
event(new WidgetInitialized('dialog'));
// In a frontend script
window.addEventListener('widgetInitialized', (e) => {
$(`#${e.detail.name}`).dialog();
});
jQuery Dependency
jquery@^3.6.0 and include jQuery UI after jQuery in your layout.CSS Conflicts
!important sparingly:
.ui-widget { all: unset !important; }
Outdated Releases
jQuery is not defined (load order issue) or Cannot read property 'widget' of undefined (missing jQuery UI).$(document).ready(function() { /* ... */ });
or use Laravel’s @stack('scripts') to defer execution.Custom Widgets
Extend jQuery UI with Laravel-specific widgets (e.g., laravel-dialog):
$.widget('ui.laravelDialog', {
_create: function() {
this.element.dialog({
buttons: {
"Save": function() { /* Laravel CSRF token handling */ }
}
});
}
});
Laravel Mix Processing Process jQuery UI assets with Laravel Mix for minification:
mix.js('resources/js/jquery-ui-init.js', 'public/js')
.sass('resources/sass/jquery-ui-theme.scss', 'public/css');
Server-Side Integration Use Laravel middleware to validate widget requests:
Route::get('/autocomplete', function() {
return response()->json([
'results' => Model::where('name', 'like', '%'.$request->term.'%')->get()
]);
})->middleware('throttle:60,1');
How can I help you explore Laravel packages today?