mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 16:13:28 +02:00
MDL-50484 lib_formslib: Persistant input should have different id
Persistant input is appended for frozen elements and should have different id then the actual element
This commit is contained in:
parent
2aacd415e1
commit
1ebda3eb8c
7 changed files with 83 additions and 5 deletions
|
@ -450,6 +450,8 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
|
|||
break;
|
||||
default:
|
||||
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN && $value) {
|
||||
// Id should be different then the actual input added later.
|
||||
$attrs['id'] .= '_hidden';
|
||||
$html .= html_writer::empty_tag('input', $attrs + array('type' => 'hidden', 'value' => $value));
|
||||
}
|
||||
// Display option as checkbox
|
||||
|
@ -461,6 +463,8 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
|
|||
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN || $mode == gradingform_rubric_controller::DISPLAY_PREVIEW) {
|
||||
$attrs['disabled'] = 'disabled';
|
||||
unset($attrs['name']);
|
||||
// Id should be different then the actual input added later.
|
||||
$attrs['id'] .= '_disabled';
|
||||
}
|
||||
$html .= html_writer::empty_tag('input', $attrs);
|
||||
$html .= html_writer::tag('label', get_string($option, 'gradingform_rubric'), array('for' => $attrs['id']));
|
||||
|
|
|
@ -130,5 +130,4 @@ class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{
|
|||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,5 +124,4 @@ class MoodleQuickForm_text extends HTML_QuickForm_text{
|
|||
function getHelpButton(){
|
||||
return $this->_helpbutton;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
|
|||
if (count($options->repositories) > 0) {
|
||||
$straddlink = get_string('choosealink', 'repository');
|
||||
$str .= <<<EOD
|
||||
<button id="filepicker-button-{$client_id}" class="visibleifjs">
|
||||
<button id="filepicker-button-js-{$client_id}" class="visibleifjs">
|
||||
$straddlink
|
||||
</button>
|
||||
EOD;
|
||||
|
|
|
@ -254,11 +254,18 @@ class HTML_QuickForm_element extends HTML_Common
|
|||
return '';
|
||||
} else {
|
||||
$id = $this->getAttribute('id');
|
||||
if (isset($id)) {
|
||||
// Id of persistant input is different then the actual input.
|
||||
$id = array('id' => $id . '_persistant');
|
||||
} else {
|
||||
$id = array();
|
||||
}
|
||||
|
||||
return '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->getValue()
|
||||
) + (isset($id)? array('id' => $id): array())) . ' />';
|
||||
) + $id) . ' />';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,4 +493,4 @@ class HTML_QuickForm_element extends HTML_Common
|
|||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_element
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -30,6 +30,7 @@ MDL-46467 - $mform->hardfreeze causes labels to loose their for HTML attribute
|
|||
MDL-52081 - made all constructors PHP7 compatible
|
||||
MDL-52826 - Remove onsubmit events pointing to the global validation functions and script
|
||||
tag moved after the HTML
|
||||
MDL-50484 - _getPersistantData() returns id with _persistant prefixed to element id.
|
||||
|
||||
|
||||
Pear
|
||||
|
|
|
@ -577,6 +577,35 @@ class core_formslib_testcase extends advanced_testcase {
|
|||
$this->assertTag(array('id' => 'id_grade_3_modgrade_point'), $html);
|
||||
$this->assertTag(array('id' => 'id_grade_3_modgrade_scale'), $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test persistant freeze elements have different id's.
|
||||
*/
|
||||
public function test_persistantrreeze_element() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$form = new formslib_persistantrreeze_element();
|
||||
ob_start();
|
||||
$form->display();
|
||||
$html = ob_get_clean();
|
||||
|
||||
// Test advcheckbox id's.
|
||||
$this->assertTag(array('id' => 'id_advcheckboxpersistant'), $html);
|
||||
$this->assertTag(array('id' => 'id_advcheckboxpersistant_persistant'), $html);
|
||||
$this->assertTag(array('id' => 'id_advcheckboxnotpersistant'), $html);
|
||||
$this->assertNotTag(array('id' => 'id_advcheckboxnotpersistant_persistant'), $html);
|
||||
$this->assertTag(array('id' => 'id_advcheckboxfrozen'), $html);
|
||||
$this->assertTag(array('id' => 'id_advcheckboxfrozen_persistant'), $html);
|
||||
|
||||
// Check text element id's.
|
||||
$this->assertTag(array('id' => 'id_textpersistant'), $html);
|
||||
$this->assertTag(array('id' => 'id_textpersistant_persistant'), $html);
|
||||
$this->assertTag(array('id' => 'id_textnotpersistant'), $html);
|
||||
$this->assertNotTag(array('id' => 'id_textnotpersistant_persistant'), $html);
|
||||
$this->assertTag(array('id' => 'id_textfrozen'), $html);
|
||||
$this->assertNotTag(array('id' => 'id_textfrozen_persistant'), $html);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -861,3 +890,42 @@ class formslib_multiple_modgrade_form extends moodleform {
|
|||
$mform->addElement('modgrade', 'grade[3]', 'Grade 3');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to test frozen elements get unique id attributes.
|
||||
*/
|
||||
class formslib_persistantrreeze_element extends moodleform {
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
// Create advanced checkbox.
|
||||
// Persistant.
|
||||
$advcheckboxpersistant = $mform->addElement('advcheckbox', 'advcheckboxpersistant', 'advcheckbox');
|
||||
$mform->setType('advcheckboxpersistant', PARAM_BOOL);
|
||||
$advcheckboxpersistant->setChecked(true);
|
||||
$advcheckboxpersistant->freeze();
|
||||
$advcheckboxpersistant->setPersistantFreeze(true);
|
||||
// Frozen.
|
||||
$advcheckboxfrozen = $mform->addElement('advcheckbox', 'advcheckboxfrozen', 'advcheckbox');
|
||||
$mform->setType('advcheckboxfrozen', PARAM_BOOL);
|
||||
$advcheckboxfrozen->setChecked(true);
|
||||
$advcheckboxfrozen->freeze();
|
||||
// Neither persistant nor Frozen.
|
||||
$mform->addElement('advcheckbox', 'advcheckboxnotpersistant', 'advcheckbox');
|
||||
$mform->setType('advcheckboxnotpersistant', PARAM_BOOL);
|
||||
|
||||
// Create text fields.
|
||||
// Persistant.
|
||||
$elpersistant = $mform->addElement('text', 'textpersistant', 'test', 'test');
|
||||
$mform->setType('textpersistant', PARAM_TEXT);
|
||||
$elpersistant->freeze();
|
||||
$elpersistant->setPersistantFreeze(true);
|
||||
// Frozen.
|
||||
$elfrozen = $mform->addElement('text', 'textfrozen', 'test', 'test');
|
||||
$mform->setType('textfrozen', PARAM_TEXT);
|
||||
$elfrozen->freeze();
|
||||
// Neither persistant nor Frozen.
|
||||
$mform->addElement('text', 'textnotpersistant', 'test', 'test');
|
||||
$mform->setType('textnotpersistant', PARAM_TEXT);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue