Modal windows (Modal)

Basic use

  1. use Dcat\Admin\Widgets\Modal;
  2. $modal = Modal::make()
  3. ->lg()
  4. ->title('TITLE')
  5. ->body(view(...))
  6. ->button('<button class="btn btn-primary">Click to open a pop-up window</button>');
  7. return view(..., ['modal' => $modal]);

Functionality

TITLE (title)

Set pop-up window TITLE

  1. $modal->title('TITLE');

content (body)

Set popup contents, this method accepts a parameter that allows incoming values of type string, Closure, Illuminate\Contracts\Support\Renderable and Dcat\Admin\Contracts\LazyRenderable.

  1. // pass a string
  2. $modal->body('字符串');
  3. // pass a closure, note that the closure must return a string type value or a null value
  4. $modal->body(function () {
  5. return view(...)->render();
  6. });
  7. // Passing in Renderable
  8. use Dcat\Admin\Widgets\
  9. $modal->body(view(...));
  10. $modal->body(Card::make());
  11. // Passing in LazyRenderable
  12. $modal->body(PostTable::make());

Bottom content (footer)

Set the content at the bottom of the popup window, this method accepts a parameter that allows the passing of string, Closure, Illuminate\Contracts\Support\Renderable and Dcat\Admin\Contracts\LazyRenderable type values, Usage as above.

  1. $modal->footer('字符串');
  2. $modal->footer(view(...));

size

  1. Default `500px`
  1. // 800px
  2. $modal->lg();
  3. // 1140px
  4. $modal->xl();

Buttons (button)

Set button

Event listening

Supported Events

  • onShow Popup Show Event
  • onShown Pop-up window shows event
  • onHide Popup hide event
  • onHidden Pop-ups with hidden event

UsageExample

  1. use Dcat\Admin\Admin;
  2. $modal->onShow(
  3. <<<JS
  4. console.log('shown a pop-up window', target, $(this));
  5. JS
  6. );
  7. $modal->onHide(
  8. <<<JS
  9. console.log('Hidden a pop-up window', target, $(this));
  10. JS
  11. );

Vertical centered (centered)

Set the pop-up window to be vertically centered

  1. $modal = Modal::make()
  2. ->xl()
  3. ->centered() // Set the pop-up window to be vertically centered
  4. ->title(...)
  5. ->body(...);

Scrollable content (scrollable)

Set the content of the pop-up window to be scrollable

  1. $modal = Modal::make()
  2. ->xl()
  3. ->scrollable() // Set the content of the pop-up window to be scrollable
  4. ->title(...)
  5. ->body(...);

Form pop-up

Reference tools-form - popups