Skip to content

Commit

Permalink
Added support for highlighting tabs with errors in them in bootstrap_…
Browse files Browse the repository at this point in the history
…tabs template.
  • Loading branch information
cheesegrits committed Apr 17, 2017
1 parent 2ce869d commit 93d6be2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
11 changes: 10 additions & 1 deletion components/com_fabrik/views/form/tmpl/bootstrap_tabs/default.php
Expand Up @@ -66,14 +66,23 @@
<?php
$i = 0;
$tabs = array();
$is_err = false;

foreach ($this->groups as $group) :
foreach ($group->elements as $element) {
if ($element->error != '') {
$is_err = true;
break;
}
}
$err_class = $is_err ? 'fabrikErrorGroup' : '';
$tabId = $this->form->id . '_' . (int)$this->rowid . '_' . $i;
// If this is multi-page then groups are consolidated until a group with a page break
// So we should only show a tab if: it is first tab, or if it is a page break
if (!$model->isMultiPage() || $i === 0 || $group->splitPage) :
$is_err = false;
$tab = new stdClass;
$tab->class = $i === 0 ? 'active' : '';
$tab->class = $i === 0 ? 'active ' . $err_class : $err_class;
$tab->css = $group->css;
$tab->href = 'group-tab' . $tabId;
$tab->id = 'group' . $group->id . '_tab';
Expand Down
Expand Up @@ -16,5 +16,27 @@
.fabrikGroup {
clear: left;
}
/* color & highlight group with validation errors */
.fabrikErrorGroup a {
background-color: rgb(242, 222, 222) !important;
color: #b94a48;
}
.active.fabrikErrorGroup a,
.active.fabrikErrorGroup a:hover,
.active.fabrikErrorGroup a:focus {
border: 1px solid #b94a48 !important;
border-bottom-color: transparent !important;
color: #b94a48 !important;
background-color: rgb(255, 255, 255) !important;
}
.fabrikErrorGroup a:hover,
.fabrikErrorGroup a:focus {
background-color: rgb(222, 173, 173) !important;
color: #b94a48;
}
";
?>
2 changes: 1 addition & 1 deletion media/com_fabrik/js/dist/element.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions media/com_fabrik/js/dist/form.js

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions media/com_fabrik/js/element.js
Expand Up @@ -648,6 +648,14 @@ define(['jquery'], function (jQuery) {
}
}

var tabDiv = this.getTabDiv();
if (tabDiv) {
var tab = this.getTab(tabDiv);
if (tab) {
tab.addClass('fabrikErrorGroup');
}
}

break;
case 'fabrikSuccess':
container.addClass('success').removeClass('info').removeClass('error');
Expand Down Expand Up @@ -888,6 +896,29 @@ define(['jquery'], function (jQuery) {
}.bind(this)).delay(500);
},

getTab: function(tab_div) {
var tab_dl;
if (Fabrik.bootstrapped) {
var a = jQuery('a[href$=#' + tab_div.id + ']');
tab_dl = a.closest('[data-role=fabrik_tab]');
} else {
tab_dl = tab_div.getPrevious('.tabs');
}
if (tab_dl) {
return tab_dl;
}
return false;
},

getTabDiv: function() {
var c = Fabrik.bootstrapped ? '.tab-pane' : '.current';
var tab_div = this.element.getParent(c);
if (tab_div) {
return tab_div;
}
return false;
},

/**
* Tabs mess with element positioning - some element (googlemaps, file upload) need to redraw themselves
* when the tab is clicked
Expand Down
1 change: 1 addition & 0 deletions media/com_fabrik/js/form.js
Expand Up @@ -1401,6 +1401,7 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
return;
}
// Process errors if there are some
jQuery(this.form.getElements('[data-role=fabrik_tab]')).removeClass('fabrikErrorGroup')
var errfound = false;
if (json.errors !== undefined) {

Expand Down

0 comments on commit 93d6be2

Please sign in to comment.