Skip to content

Commit

Permalink
MDL-55656 theme_noname: Include advanced and required field markup
Browse files Browse the repository at this point in the history
The new form elements were not including the markup for advanced
and required fields. I used an <abbr> tag in the label to give
and accessible indication of the advanced and required fields.

Part of MDL-55071
  • Loading branch information
Damyon Wiese authored and danpoltawski committed Sep 23, 2016
1 parent 072364d commit d6f2ce1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/form/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function export_for_template(renderer_base $output) {
}
}

$out = $OUTPUT->mform_element($element, false, '', true);
$out = $OUTPUT->mform_element($element, false, false, '', true);

if (empty($out)) {
$renderer = new HTML_QuickForm_Renderer_Default();
Expand Down
6 changes: 4 additions & 2 deletions lib/formslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2774,8 +2774,9 @@ function startGroup(&$group, $required, $error){

// Update the ID.
$group->updateAttributes(array('id' => $groupid));
$advanced = isset($this->_advancedElements[$group->getName()]);

$html = $OUTPUT->mform_element($group, $required, $error, false);
$html = $OUTPUT->mform_element($group, $required, $advanced, $error, false);
$fromtemplate = !empty($html);
if (!$fromtemplate) {
if (method_exists($group, 'getElementTemplateType')) {
Expand Down Expand Up @@ -2833,8 +2834,9 @@ function renderElement(&$element, $required, $error){

// Make sure the element has an id.
$element->_generateId();
$advanced = isset($this->_advancedElements[$element->getName()]);

$html = $OUTPUT->mform_element($element, $required, $error, false);
$html = $OUTPUT->mform_element($element, $required, $advanced, $error, false);
$fromtemplate = !empty($html);
if (!$fromtemplate) {
// Adding stuff to place holders in template
Expand Down
4 changes: 3 additions & 1 deletion lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4426,11 +4426,12 @@ public function render_login(\core\output\login $form) {
*
* @param HTML_QuickForm_element $element element
* @param bool $required if input is required field
* @param bool $advanced if input is an advanced field
* @param string $error error message to display
* @param bool $ingroup True if this element is rendered as part of a group
* @return mixed string|bool
*/
public function mform_element($element, $required, $error, $ingroup) {
public function mform_element($element, $required, $advanced, $error, $ingroup) {
$templatename = 'core_form/element-' . $element->getType();
if ($ingroup) {
$templatename .= "-inline";
Expand All @@ -4456,6 +4457,7 @@ public function mform_element($element, $required, $error, $ingroup) {
'element' => $elementcontext,
'label' => $label,
'required' => $required,
'advanced' => $advanced,
'helpbutton' => $helpbutton,
'error' => $error
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="form-group {{#error}}has-danger{{/error}} fitem">
<div class="form-group {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}}">
<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}}">✲</abbr>{{/required}}
{{#advanced}}<abbr class="initialism text-info" title="{{#str}}advanced{{/str}}">❗</abbr>{{/advanced}}
</label>
{{$ element }}
<!-- Element goes here -->
Expand Down
9 changes: 7 additions & 2 deletions theme/noname/templates/core_form/element-template.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<div class="form-group row {{#error}}has-danger{{/error}} fitem">
<div class="form-group row {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}}">
<label class="col-md-3 col-form-label {{#element.hiddenlabel}}sr-only{{/element.hiddenlabel}}" for="{{element.id}}">
{{{label}}} {{{helpbutton}}}
{{{label}}}
<span class="pull-xs-right">
{{{helpbutton}}}
{{#required}}<abbr class="initialism text-danger" title="{{#str}}required{{/str}}">✲</abbr>{{/required}}
{{#advanced}}<abbr class="initialism text-info" title="{{#str}}advanced{{/str}}">❗</abbr>{{/advanced}}
</span>
</label>
<div class="col-md-9 form-inline felement">
{{$ element }}
Expand Down

0 comments on commit d6f2ce1

Please sign in to comment.