class ModalJQry extends Widget { // @var array Options for modal. public array $options…
- User
class ModalJQry extends Widget { // @var array Options for modal. public array $options = [];
// @var string Modal title public string $title = 'Modal Title'; // @var string Modal size public string $size = 'modal-lg'; // This property will hold the instance of the form model passed public object $formModel; // Optional property to enforce a specific form model class public ?string $expectedFormModelClass = null; // Default modal view public string $view = '_defaultModal'; // View params public array $viewParams = []; /** * Runs the widget and renders the modal with the form. * @return void */ public function run(): void { // @var ID string - Generate a unique ID for the input field if not provided. $id = $this->options['id'] ?? $this->getId(); // Render the Bootstrap modal. BootstrapModal::begin([ 'id' => $id, 'title' => $this->title, 'options' => [ 'class' => ['modal fade square'] ], 'size' => $this->size, ]); }}
I want to take advantage more of the $options = array and use it more within the BootstrapModal::begin([]); thoughts?
- Assistant
- User
this is for yii2 use yii\bootstrap5\Modal as BootstrapModal;
- Assistant
- User
- Assistant
- User
resend the code again
- Assistant
- User
what is the keyboard option
- Assistant
The
keyboardoption in Bootstrap modals (and thus in Yii2's Bootstrap widgets) controls whether pressing the Escape (Esc) key will close the modal.
Details:
- Type:
boolean - Default:
true - Meaning:
true— the modal can be closed by pressing the Escape key.false— pressing Escape will not close the modal.
Example Usage
Modal::begin([ 'keyboard' => false, // Disable closing modal with Escape key // other options... ]);In this example, the modal remains open even if the user hits Escape, which can be useful if you want to force the user to interact with buttons or form fields instead of accidentally closing via keyboard.
Bootstrap 5 Docs Reference
- Type:
- User
/** * @var array Options for modal configuration and container HTML attributes. * Supported keys include: * - 'id' => string, modal HTML id (generated if not provided) * - 'title' => string, modal header title (overrides this->size) * - 'backdrop' => bool|string, Bootstrap modal backdrop option * - 'keyboard' => bool, Bootstrap modal keyboard option * - 'centered' => bool, Bootstrap modal centered option * - 'scrollable' => bool, Bootstrap modal scrollable option * - 'fade' => bool, Bootstrap modal fade animation option * - 'options' => array, HTML attributes for the modal container tag (e.g. ['class' => 'custom-class']) */
- Assistant
Certainly! Here's an expanded version of your PHPDoc block for the
$optionsproperty including detailed explanation of the option along with the others, describing what each does in terms of Bootstrap modal behavior: