Remove hard coded widget name for lazy tabs (#4839)

- The widget alias may not always be form, so pass the handler name
- No need to spam non-lazy tabs with useless data tags
This commit is contained in:
Samuel Georges 2019-12-22 16:36:04 +11:00
parent 3a49b5fa7a
commit 953061797d
2 changed files with 15 additions and 7 deletions

View File

@ -167,8 +167,10 @@
*/
FormWidget.prototype.bindLazyTabs = function() {
this.$el.on('click', '.tab-lazy [data-toggle="tab"]', function() {
var $el = $(this)
$.request('form::onLazyLoadTab', {
var $el = $(this),
handlerName = $el.data('tab-lazy-handler')
$.request(handlerName, {
data: {
target: $el.data('target'),
name: $el.data('tab-name'),

View File

@ -13,12 +13,18 @@
?>
<div class="<?= $navCss ?>">
<ul class="nav nav-tabs">
<?php $index = 0; foreach ($tabs as $name => $fields): ?>
<?php
$lazy = in_array($name, $tabs->lazy);
?>
<?php $index = 0; foreach ($tabs as $name => $fields):
$lazy = in_array($name, $tabs->lazy);
?>
<li class="<?= ($index++ === 0) ? 'active' : '' ?> <?= $lazy ? 'tab-lazy' : '' ?>">
<a href="#<?= $type . 'tab-' . $index ?>" data-tab-name="<?= e($name) ?>" data-tab-section="<?= $type ?>">
<a
href="#<?= $type . 'tab-' . $index ?>"
<?php if ($lazy): ?>
data-tab-name="<?= e($name) ?>"
data-tab-section="<?= $type ?>"
data-tab-lazy-handler="<?= $this->getEventHandler('onLazyLoadTab') ?>"
<?php endif ?>
>
<span class="title">
<span>
<?php if ($tabs->getIcon($name)): ?><span class="<?= $tabs->getIcon($name) ?>"></span><?php endif; ?>