Commit 766d6f9a authored by Davo Smith's avatar Davo Smith
Browse files

MDL-53848 form: hide entire group if hideIf test is applied to the group

parent 98887965
......@@ -85,6 +85,13 @@ if (typeof M.form.dependencyManager === 'undefined') {
names[name].push(node);
}
});
// Locate any groups with the given name.
this.get('form').all('.fitem').each(function(node) {
var name = node.getData('groupname');
if (name && ({}).hasOwnProperty.call(names, name)) {
names[name].push(node);
}
});
this._nameCollections = names;
},
......@@ -264,7 +271,7 @@ if (typeof M.form.dependencyManager === 'undefined') {
_hideElement: function(name, hidden) {
var els = this.elementsByName(name);
els.each(function(node) {
var e = node.ancestor('.fitem');
var e = node.ancestor('.fitem', true);
if (e) {
(hidden) ? e.setAttribute('hidden', 'hidden') : e.removeAttribute('hidden');
e.setStyles({
......
......@@ -213,6 +213,7 @@ class MoodleQuickForm_group extends HTML_QuickForm_group implements templatable
$i++;
}
$context['groupname'] = $name;
$context['elements'] = $elements;
return $context;
}
......
......@@ -46,7 +46,7 @@
}
}}
<div id="fitem_{{ element.id }}" class="fitem fitem_{{ element.type }}">
<div id="fitem_{{ element.id }}" class="fitem fitem_{{ element.type }}" {{#element.groupname}}data-groupname="{{.}}"{{/element.groupname}}>
<div class="fitemtitle">
<label for="{{element.id}}">{{{ label }}}</label>
{{{ helpbutton }}}
......
......@@ -2466,9 +2466,9 @@ require(["core/event", "jquery"], function(Event, $) {
$result[$dependenton][$condition][$value][self::DEP_HIDE] = array();
foreach ($dependents as $dependent) {
$elements = $this->_getElNamesRecursive($dependent);
if (empty($elements)) {
// Probably element inside of some group.
$elements = array($dependent);
if (!in_array($dependent, $elements)) {
// Always want to hide the main element, even if it contains sub-elements as well.
$elements[] = $dependent;
}
foreach ($elements as $element) {
if ($element == $dependenton) {
......
<div class="form-group {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}} {{{element.extraclasses}}}">
<div class="form-group {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}} {{{element.extraclasses}}}" {{#element.groupname}}data-groupname="{{.}}"{{/element.groupname}}>
<label class="col-form-label {{#element.hiddenlabel}}sr-only{{/element.hiddenlabel}}" for="{{element.id}}">
{{{label}}} {{{helpbutton}}}
{{#required}}<abbr class="initialism text-danger" title="{{#str}}required{{/str}}">{{#pix}}req, core, {{#str}}required{{/str}}{{/pix}}</abbr>{{/required}}
......
......@@ -41,7 +41,7 @@
}
}
}}
<div class="form-group row {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}} {{{element.extraclasses}}}">
<div class="form-group row {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}} {{{element.extraclasses}}}" {{#element.groupname}}data-groupname="{{.}}"{{/element.groupname}}>
<div class="col-md-3">
<span class="pull-xs-right text-nowrap">
{{#required}}<abbr class="initialism text-danger" title="{{#str}}required{{/str}}">{{#pix}}req, core, {{#str}}required{{/str}}{{/pix}}</abbr>{{/required}}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment