contao-components/jquery-ui
Contao-managed distribution of jQuery UI components for use in Contao CMS projects. Provides the jQuery UI library packaged via Composer, making it easy to include common UI widgets, effects, and interactions in your frontend build.
Installation Add the package via Composer:
composer require contao-components/jquery-ui
Publish the assets (if using Laravel Mix or Vite):
npm install jquery-ui-dist
Basic Usage
Include jQuery and jQuery UI in your layout (e.g., resources/js/app.js):
import 'jquery-ui-dist/jquery-ui';
Or via CDN in a Blade template:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
First Widget Initialize a simple dialog in a Blade view:
<button id="open-dialog">Open Dialog</button>
<div id="dialog" title="Basic dialog" style="display: none;">
Hello, jQuery UI!
</div>
<script>
$(function() {
$("#dialog").dialog();
});
</script>
Laravel Mix/Vite Integration
Add to webpack.mix.js:
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', []);
Ensure jquery-ui is imported in your entry file.
Dynamic Widget Initialization Use Laravel Blade directives or Alpine.js to conditionally load widgets:
@if(auth()->check())
<div id="user-panel" style="display: none;">
<p>Welcome, {{ auth()->user()->name }}!</p>
</div>
<script>
$(function() {
$("#user-panel").dialog({ autoOpen: false });
$("#open-panel").click(() => $("#user-panel").dialog("open"));
});
</script>
@endif
Form Integration Enhance Laravel form validation with jQuery UI:
<form id="my-form">
<input type="text" name="username" required>
<button type="submit">Submit</button>
</form>
<script>
$(function() {
$("#my-form").validate({
rules: { username: { required: true } },
messages: { username: "Please enter a username" },
submitHandler: function(form) {
$.ajax({
url: "{{ route('form.submit') }}",
method: "POST",
data: $(form).serialize(),
});
}
});
// Add jQuery UI styling to error messages
$(".error").dialog({ modal: true, buttons: { Ok: function() { $(this).dialog("close"); } } });
});
</script>
AJAX-Driven Widgets Load widgets dynamically via Laravel routes:
// Example: Lazy-load a sortable list
$("#load-sortable").click(function() {
$.get("{{ route('admin.sortable.items') }}", function(data) {
$("#sortable-list").html(data).sortable({
update: function() {
$.post("{{ route('admin.sortable.update') }}", $(this).sortable("serialize"));
}
});
});
});
Laravel Blade + jQuery UI Pass data from Laravel to jQuery UI widgets:
<div id="user-list" style="display: none;">
@foreach($users as $user)
<div class="user-item" data-id="{{ $user->id }}">
{{ $user->name }}
</div>
@endforeach
</div>
<script>
$(function() {
$("#user-list").dialog({
title: "Users ({{ $users->count() }})",
width: 600
});
});
</script>
Laravel Mix/Vite
jquery-ui/dist/jquery-ui.css for themes (e.g., jquery-ui/themes/base/all.css).mix.copy('node_modules/jquery-ui-dist/themes/base', 'public/css/jquery-ui');
Laravel Echo/Pusher Update widgets in real-time:
Echo.channel('user-updates')
.listen('UserUpdated', (e) => {
$("#user-panel").dialog("option", "title", `Updated: ${e.user.name}`);
});
Laravel Validation
Sync jQuery UI validation with Laravel’s FormRequest:
$("#my-form").validate({
rules: {
email: { required: true, email: true },
password: { minlength: 8 }
},
errorElement: "span",
errorPlacement: function(error, element) {
error.addClass("ui-state-error").insertAfter(element);
}
});
Laravel Livewire/Alpine Combine with Livewire for reactive UI:
<div x-data="{ open: false }">
<button @click="open = true">Open Modal</button>
<div x-show="open" @click.away="open = false" class="ui-dialog">
<!-- jQuery UI dialog content -->
</div>
</div>
jQuery Conflicts
$.noConflict() if needed:
var jqu = $.noConflict();
jqu("#dialog").dialog();
CSS Overrides
.ui-widget { font-family: 'Inter', sans-serif; }
Lazy Loading Issues
$(document).on("ajaxSuccess", function() {
$("#dynamic-dialog").dialog();
});
Laravel Mix Caching
npm run dev -- --no-cache
Theme Loading
import 'jquery-ui-dist/jquery-ui.css';
import 'jquery-ui-dist/themes/base/all.css'; // Explicit theme
Console Errors
jQuery is not defined (missing jQuery).$.ui.dialog for jQuery UI 1.13+).Network Tab
jquery-ui.min.js).Laravel Logs
Widget Initialization
$(document).ready(function() { ... });
// or
$(function() { ... });
Custom Themes
// resources/scss/jquery-ui.scss
@import "~jquery-ui-dist/themes/base/theme.scss";
$primary-color: #6c5ce7;
Laravel Service Provider
AppServiceProvider:
public function boot()
{
View::composer('*', function ($view) {
$view->with(['jqueryUi' => [
'dialog' => ['autoOpen' => false],
'sortable' => ['cursor' => 'move']
]]);
});
}
Laravel Blade Directives Create a directive for reusable widgets:
// app/Providers/BladeServiceProvider.php
Blade::directive('jqueryUi', function ($expression) {
return "<?php echo \$__env->make('components.jquery-ui', ['widget' => $expression])->render(); ?>";
});
Usage:
@jqueryUi('dialog', ['title' => 'Custom'])
Laravel Livewire Components Integrate with Livewire for reactive widgets:
// app/Http/Livewire/UserPanel.php
public function mount()
{
$this->widgetOptions = ['title' => 'User Panel'];
}
public function render()
{
return view('livewire.user-panel', [
'options' => $this->widgetOptions
]);
}
<!-- resources/views/livewire/user-panel.blade.php -->
<div x-data="{ open: false }">
<button @click="open = true">Open</button>
<div x-show="open"
How can I help you explore Laravel packages today?