mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-71336 forms: ensure grouped date elements have unique IDs.
Previously they were each taking the ID of their parent group element.
This commit is contained in:
parent
94ad185d09
commit
773bfa9272
@ -130,11 +130,12 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group {
|
||||
// If optional we add a checkbox which the user can use to turn if on.
|
||||
if ($this->_options['optional']) {
|
||||
$this->_elements[] = $this->createFormElement('checkbox', 'enabled', null,
|
||||
get_string('enable'), $this->getAttributes(), true);
|
||||
get_string('enable'), $this->getAttributesForFormElement(), true);
|
||||
}
|
||||
foreach ($dateformat as $key => $value) {
|
||||
// E_STRICT creating elements without forms is nasty because it internally uses $this
|
||||
$this->_elements[] = $this->createFormElement('select', $key, get_string($key, 'form'), $value, $this->getAttributes(), true);
|
||||
$this->_elements[] = $this->createFormElement('select', $key, get_string($key, 'form'), $value,
|
||||
$this->getAttributesForFormElement(), true);
|
||||
}
|
||||
// The YUI2 calendar only supports the gregorian calendar type so only display the calendar image if this is being used.
|
||||
if ($calendartype->get_name() === 'gregorian') {
|
||||
|
@ -134,26 +134,27 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group {
|
||||
// If optional we add a checkbox which the user can use to turn if on.
|
||||
if ($this->_options['optional']) {
|
||||
$this->_elements[] = $this->createFormElement('checkbox', 'enabled', null,
|
||||
get_string('enable'), $this->getAttributes(), true);
|
||||
get_string('enable'), $this->getAttributesForFormElement(), true);
|
||||
}
|
||||
$dateformat = $calendartype->get_date_order($this->_options['startyear'], $this->_options['stopyear']);
|
||||
if (right_to_left()) { // Display time to the right of date, in RTL mode.
|
||||
$this->_elements[] = $this->createFormElement('select', 'minute', get_string('minute', 'form'),
|
||||
$minutes, $this->getAttributes(), true);
|
||||
$minutes, $this->getAttributesForFormElement(), true);
|
||||
$this->_elements[] = $this->createFormElement('select', 'hour', get_string('hour', 'form'),
|
||||
$hours, $this->getAttributes(), true);
|
||||
$hours, $this->getAttributesForFormElement(), true);
|
||||
// Reverse date element (Should be: Day, Month, Year), in RTL mode.
|
||||
$dateformat = array_reverse($dateformat);
|
||||
}
|
||||
foreach ($dateformat as $key => $date) {
|
||||
// E_STRICT creating elements without forms is nasty because it internally uses $this
|
||||
$this->_elements[] = $this->createFormElement('select', $key, get_string($key, 'form'), $date, $this->getAttributes(), true);
|
||||
$this->_elements[] = $this->createFormElement('select', $key, get_string($key, 'form'), $date,
|
||||
$this->getAttributesForFormElement(), true);
|
||||
}
|
||||
if (!right_to_left()) { // Display time to the left of date, in LTR mode.
|
||||
$this->_elements[] = $this->createFormElement('select', 'hour', get_string('hour', 'form'), $hours,
|
||||
$this->getAttributes(), true);
|
||||
$this->getAttributesForFormElement(), true);
|
||||
$this->_elements[] = $this->createFormElement('select', 'minute', get_string('minute', 'form'), $minutes,
|
||||
$this->getAttributes(), true);
|
||||
$this->getAttributesForFormElement(), true);
|
||||
}
|
||||
// The YUI2 calendar only supports the gregorian calendar type so only display the calendar image if this is being used.
|
||||
if ($calendartype->get_name() === 'gregorian') {
|
||||
|
@ -172,10 +172,7 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
|
||||
* Override of standard quickforms method to create this element.
|
||||
*/
|
||||
function _createElements() {
|
||||
$attributes = $this->getAttributes();
|
||||
if (is_null($attributes)) {
|
||||
$attributes = [];
|
||||
}
|
||||
$attributes = $this->getAttributesForFormElement();
|
||||
if (!isset($attributes['size'])) {
|
||||
$attributes['size'] = 3;
|
||||
}
|
||||
@ -191,7 +188,7 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
|
||||
// If optional we add a checkbox which the user can use to turn if on
|
||||
if($this->_options['optional']) {
|
||||
$this->_elements[] = $this->createFormElement('checkbox', 'enabled', null,
|
||||
get_string('enable'), $this->getAttributes(), true);
|
||||
get_string('enable'), $attributes, true);
|
||||
}
|
||||
foreach ($this->_elements as $element){
|
||||
if (method_exists($element, 'setHiddenLabel')){
|
||||
|
@ -155,6 +155,16 @@ class MoodleQuickForm_group extends HTML_QuickForm_group implements templatable
|
||||
return call_user_func_array([$this->_mform, 'createElement'], func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return attributes suitable for passing to {@see createFormElement}, comprised of all group attributes without ID in
|
||||
* order to ensure uniqueness of that value within the group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributesForFormElement(): array {
|
||||
return array_diff_key((array) $this->getAttributes(), array_flip(['id']));
|
||||
}
|
||||
|
||||
public function export_for_template(renderer_base $output) {
|
||||
global $OUTPUT;
|
||||
|
||||
|
7
lib/form/upgrade.txt
Normal file
7
lib/form/upgrade.txt
Normal file
@ -0,0 +1,7 @@
|
||||
This files describes API changes in core_form libraries and APIs,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 4.1.7 ===
|
||||
|
||||
* The group element has a new method `getAttributesForFormElement` which should be used in conjunction
|
||||
with `createFormElement` to ensure that all elements within the group have unique IDs
|
Loading…
x
Reference in New Issue
Block a user