Download the PHP package rft/yii2-alert-modal-widget without Composer
On this page you can find all versions of the php package rft/yii2-alert-modal-widget. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rft/yii2-alert-modal-widget
More information about rft/yii2-alert-modal-widget
Files in rft/yii2-alert-modal-widget
Package yii2-alert-modal-widget
Short Description A standalone, reusable modal widget for Yii2 Framework with SweetAlert-like UI for confirmation dialogs.
License MIT
Informations about the package yii2-alert-modal-widget
Yii2 Alert Modal Widget
A standalone, reusable confirmation modal widget for the Yii2 Framework with SweetAlert-like UI/UX. This widget is completely independent of Bootstrap and includes its own CSS and JavaScript.
Features
- No Bootstrap Dependency: Uses custom CSS and JavaScript - no Bootstrap required
- SweetAlert2-like UI: Clean, modern interface with centered layout and icons
- Standalone Implementation: All styles and scripts are self-contained within the widget
- Icon Support: Five icon types (question, warning, success, error, info) with customizable colors
- Dynamic Content: Modal content can be customized per trigger via data attributes
- POST Method Support: Handles POST requests with CSRF token integration
- Responsive Design: Mobile-friendly layout with proper breakpoints
- Multiple Instances: Support for different modal types with separate configurations
Installation
This is an internal widget for your Yii2 application. To use it:
- Copy the
AlertModalWidget.phpfile to yourfrontend/components/widgets/directory - Ensure Font Awesome is included in your project (for icons)
No Bootstrap required! The widget includes all necessary CSS and JavaScript.
Basic Usage
Step 1: Define Your Modals
Place modal widgets in your view or layout file. Note the button class format:
Step 2: Create Trigger Buttons
Create buttons/links with the corresponding CSS class. Use standard Bootstrap classes for your buttons, but add the modal trigger class:
Complete Working Example
Here's exactly how you should implement it:
Your Specific Use Case Example
Based on your code, here's exactly how to implement it:
Configuration Options
Widget Properties
| Property | Type | Default | Description |
|---|---|---|---|
triggerSelector |
string | required | CSS selector for trigger elements |
title |
string | 'Confirmation' | Default modal title |
body |
string | 'Are you sure you want to proceed?' | Default modal body text |
iconType |
string | 'question' | Icon type: 'question', 'warning', 'success', 'error', 'info' |
iconColor |
string | '#87adbd' | Custom icon color (hex) |
confirmButtonLabel |
string | 'Confirm' | Confirmation button label |
confirmButtonClass |
string | 'alert-modal-btn-confirm' | Must start with 'alert-modal-btn-confirm' |
cancelButtonLabel |
string | 'Cancel' | Cancel button label |
cancelButtonClass |
string | 'alert-modal-btn-cancel' | CSS classes for cancel button |
modalSize |
string | 'modal-md' | Modal size: 'modal-sm', 'modal-md', 'modal-lg', 'modal-xl' |
modalOptions |
array | [] | Additional modal options |
Button Classes Format
Important: The confirmButtonClass must follow this format:
Available color classes (add after the base class):
btn-danger(Red) - For delete/destructive actionsbtn-success(Green) - For success/positive actionsbtn-primary(Blue) - For primary actionsbtn-warning(Yellow) - For warning actionsbtn-info(Teal) - For informational actions
Data Attributes for Dynamic Overrides
Use these attributes on your trigger buttons/links:
| Attribute | Example | Description |
|---|---|---|
data-alert-modal-title |
data-alert-modal-title="Custom Title" |
Override modal title |
data-alert-modal-body |
data-alert-modal-body="Custom message" |
Override modal body text |
data-alert-modal-confirm-label |
data-alert-modal-confirm-label="Yes, Proceed" |
Override confirm button label |
data-alert-modal-confirm-class |
data-alert-modal-confirm-class="btn-warning" |
Add CSS classes to confirm button |
data-alert-modal-icon |
data-alert-modal-icon="warning" |
Override icon type |
data-alert-modal-icon-color |
data-alert-modal-icon-color="#ff0000" |
Override icon color |
data-method |
data-method="post" |
HTTP method for the action |
data-params |
data-params='{"key":"value"}' |
Additional POST parameters |
data-title (legacy) |
data-title="Legacy Title" |
Legacy title override (backward compatible) |
data-confirm (legacy) |
data-confirm="Legacy message" |
Legacy body override (backward compatible) |
data-confirm-label (legacy) |
data-confirm-label="Legacy Label" |
Legacy label override (backward compatible) |
Important Notes for Your Implementation
-
Button Class Format is CRITICAL:
-
Trigger Buttons Use Regular Bootstrap Classes:
-
Font Awesome Required: The widget uses Font Awesome for icons:
-
CSRF Protection: For POST requests, ensure CSRF meta tags are in your layout:
- Multiple Widgets Work Fine: The latest version has fixed the JavaScript class conflict issue.
Troubleshooting Common Issues
Modal Doesn't Show
- Check browser console for JavaScript errors
- Ensure
confirmButtonClassstarts withalert-modal-btn-confirm - Verify trigger selector matches your button class
Styling Issues
- Make sure you're not loading conflicting CSS
- Check that button classes follow the correct format
- Verify Font Awesome is loaded for icons
POST Requests Not Working
- Ensure CSRF meta tags are present
- Verify
data-method="post"is set on trigger links
The README is now updated to accurately reflect your current standalone widget implementation.