Permalink
Browse files

Merge branch 'MDL-30335' of git://github.com/timhunt/moodle

  • Loading branch information...
2 parents d2b5a2c + fa2fa5c commit 5cde86faa931d88fa7ddd64b2b79f52b72ed87ab @nebgor nebgor committed Nov 23, 2011
Showing with 29 additions and 12 deletions.
  1. +29 −12 lib/formslib.php
View
@@ -900,6 +900,29 @@ function validation($data, $files) {
return array();
}
+ /**
+ * Helper used by {@link repeat_elements()}.
+ * @param int $i the index of this element.
+ * @param HTML_QuickForm_element $elementclone
+ */
+ function repeat_elements_fix_clone($i, $elementclone, &$namecloned) {
+ $name = $elementclone->getName();
+ $namecloned[] = $name;
+
+ if (!empty($name)) {
+ $elementclone->setName($name."[$i]");
+ }
+
+ if (is_a($elementclone, 'HTML_QuickForm_header')) {
+ $value = $elementclone->_text;
+ $elementclone->setValue(str_replace('{no}', ($i+1), $value));
+
+ } else {
+ $value=$elementclone->getLabel();
+ $elementclone->setLabel(str_replace('{no}', ($i+1), $value));
+ }
+ }
+
/**
* Method to add a repeating group of elements to a form.
*
@@ -942,19 +965,13 @@ function repeat_elements($elementobjs, $repeats, $options, $repeathiddenname,
for ($i = 0; $i < $repeats; $i++) {
foreach ($elementobjs as $elementobj){
$elementclone = fullclone($elementobj);
- $name = $elementclone->getName();
- $namecloned[] = $name;
- if (!empty($name)) {
- $elementclone->setName($name."[$i]");
- }
- if (is_a($elementclone, 'HTML_QuickForm_header')) {
- $value = $elementclone->_text;
- $elementclone->setValue(str_replace('{no}', ($i+1), $value));
-
- } else {
- $value=$elementclone->getLabel();
- $elementclone->setLabel(str_replace('{no}', ($i+1), $value));
+ $this->repeat_elements_fix_clone($i, $elementclone, $namecloned);
+ if ($elementclone instanceof HTML_QuickForm_group && !$elementclone->_appendName) {
+ foreach ($elementclone->getElements() as $el) {
+ $this->repeat_elements_fix_clone($i, $el, $namecloned);
+ }
+ $elementclone->setLabel(str_replace('{no}', $i + 1, $elementclone->getLabel()));
}
$mform->addElement($elementclone);

0 comments on commit 5cde86f

Please sign in to comment.