Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Accessibility: add aria-required attribute to JFormField #1764

Merged
merged 4 commits into from Mar 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions libraries/joomla/form/fields/accesslevel.php
Expand Up @@ -47,6 +47,7 @@ protected function getInput()
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
Expand Down
5 changes: 5 additions & 0 deletions libraries/joomla/form/fields/calendar.php
Expand Up @@ -69,6 +69,11 @@ protected function getInput()
{
$attributes['onchange'] = (string) $this->element['onchange'];
}
if ($this->required)
{
$attributes['required'] = 'required';
$attributes['aria-required'] = 'true';
}

// Handle the special case for "now".
if (strtoupper($this->value) == 'NOW')
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/checkbox.php
Expand Up @@ -44,6 +44,7 @@ protected function getInput()
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$value = $this->element['value'] ? (string) $this->element['value'] : '1';
$required = $this->required ? ' required="required" aria-required="true"' : '';

if (empty($this->value))
{
Expand All @@ -58,6 +59,6 @@ protected function getInput()
$onclick = $this->element['onclick'] ? ' onclick="' . (string) $this->element['onclick'] . '"' : '';

return '<input type="checkbox" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $class . $checked . $disabled . $onclick . ' />';
. htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $class . $checked . $disabled . $onclick . $required . ' />';
}
}
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/checkboxes.php
Expand Up @@ -74,14 +74,15 @@ protected function getInput()
$checked = (in_array((string) $option->value, $value) ? ' checked="checked"' : '');
}
$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
$required = !empty($option->required) ? ' required="required" aria-required="true"' : '';
$disabled = !empty($option->disable) ? ' disabled="disabled"' : '';

// Initialize some JavaScript option attributes.
$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';

$html[] = '<li>';
$html[] = '<input type="checkbox" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="'
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>';
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . $required . '/>';

$html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . JText::_($option->text) . '</label>';
$html[] = '</li>';
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/color.php
Expand Up @@ -41,6 +41,7 @@ protected function getInput()
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$classes = (string) $this->element['class'];
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';

if (!$disabled)
{
Expand All @@ -60,6 +61,6 @@ protected function getInput()
$class = $classes ? ' class="' . trim($classes) . '"' : '';

return '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $onchange . '/>';
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $onchange . $required . '/>';
}
}
1 change: 1 addition & 0 deletions libraries/joomla/form/fields/combo.php
Expand Up @@ -46,6 +46,7 @@ protected function getInput()
$attr .= ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/email.php
Expand Up @@ -44,11 +44,12 @@ protected function getInput()
$class = $this->element['class'] ? ' ' . (string) $this->element['class'] : '';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';

return '<input type="text" name="' . $this->name . '" class="validate-email' . $class . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $size . $disabled . $readonly . $onchange . $maxLength . '/>';
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $size . $disabled . $readonly . $onchange . $maxLength . $required . '/>';
}
}
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/file.php
Expand Up @@ -47,11 +47,12 @@ protected function getInput()
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';

return '<input type="file" name="' . $this->name . '" id="' . $this->id . '"' . ' value=""' . $accept . $disabled . $class . $size
. $onchange . ' />';
. $onchange . $required . ' />';
}
}
1 change: 1 addition & 0 deletions libraries/joomla/form/fields/groupedlist.php
Expand Up @@ -143,6 +143,7 @@ protected function getInput()
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
Expand Down
1 change: 1 addition & 0 deletions libraries/joomla/form/fields/list.php
Expand Up @@ -51,6 +51,7 @@ protected function getInput()

$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/password.php
Expand Up @@ -47,6 +47,7 @@ protected function getInput()
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$meter = ((string) $this->element['strengthmeter'] == 'true');
$threshold = $this->element['threshold'] ? (int) $this->element['threshold'] : 66;
$required = $this->required ? ' required="required" aria-required="true"' : '';

$script = '';

Expand All @@ -65,6 +66,6 @@ protected function getInput()

return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' .
' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' .
$auto . $class . $readonly . $disabled . $size . $maxLength . '/>' . $script;
$auto . $class . $readonly . $disabled . $size . $maxLength . $required . '/>' . $script;
}
}
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/radio.php
Expand Up @@ -56,12 +56,13 @@ protected function getInput()
$checked = ((string) $option->value == (string) $this->value) ? ' checked="checked"' : '';
$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
$disabled = !empty($option->disable) ? ' disabled="disabled"' : '';
$required = !empty($option->required) ? ' required="required" aria-required="true"' : '';

// Initialize some JavaScript option attributes.
$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';

$html[] = '<input type="radio" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="'
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>';
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . $required . '/>';

$html[] = '<label for="' . $this->id . $i . '"' . $class . '>'
. JText::alt($option->text, preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)) . '</label>';
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/text.php
Expand Up @@ -44,11 +44,12 @@ protected function getInput()
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';

return '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . '/>';
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . $required . '/>';
}
}
3 changes: 2 additions & 1 deletion libraries/joomla/form/fields/textarea.php
Expand Up @@ -43,11 +43,12 @@ protected function getInput()
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$columns = $this->element['cols'] ? ' cols="' . (int) $this->element['cols'] . '"' : '';
$rows = $this->element['rows'] ? ' rows="' . (int) $this->element['rows'] . '"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';

return '<textarea name="' . $this->name . '" id="' . $this->id . '"' . $columns . $rows . $class . $disabled . $onchange . '>'
return '<textarea name="' . $this->name . '" id="' . $this->id . '"' . $columns . $rows . $class . $disabled . $onchange . $required . '>'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>';
}
}
1 change: 1 addition & 0 deletions libraries/joomla/form/fields/usergroup.php
Expand Up @@ -45,6 +45,7 @@ protected function getInput()
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';

// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/unit/joomla/form/JFormTest.php
Expand Up @@ -1050,7 +1050,7 @@ public function testGetInput()

$this->assertThat(
$form->getInput('title', null, 'The Title'),
$this->equalTo('<input type="text" name="title" id="title_id" value="The Title" class="inputbox required"/>'),
$this->equalTo('<input type="text" name="title" id="title_id" value="The Title" class="inputbox required" required="required" aria-required="true"/>'),
'Line:' . __LINE__ . ' The method should return a simple input text field.'
);

Expand Down