Multiple repeat element in moodle mform issue

Multiple repeat element in moodle mform issue

by Dinesh Durai -
Number of replies: 0
Picture of Core developers

I am developing a page using moodle mform. In my form, i am using three  repeat elements. In the form, if I try to add fields using this repeat elements new fields are added to all the three repeat elements. instead of adding fields for that specific one repeat element. can anyone help me in overcome this issue. I am attaching my code and image where you can find all details

Sample code:

		if ($this->_instance){
print_object("count---".$DB->count_records('choice_options', array('choiceid'=>$this->_instance)));
$repeatno = $DB->count_records('choice_options', array('choiceid'=>$this->_instance));
$repeatno += 1;
} else {
$repeatno = 1;
}

$repeateloptionsfield = array();
$repeateloptionsfield['fieldname']['type'] = PARAM_RAW;

$this->repeat_elements($textarray, $repeatno,$repeateloptionsfield, 'option_repeats1', 'option_add_fields', 1, null, true);

$mform->addElement( 'header', 'header_constructor', "Define Constructor" );

$constructor=array();
$constructor[] = &$mform->createElement('text', 'constructoraccessspecifier', get_string('constructoracc',VPL));
$constructor[] = &$mform->createElement('text', 'constructorparametertype', get_string('constparam',VPL));
//print_object("this---".$this);
if ($this->_instance){

print_object($this->_instance);
print_object($DB->count_records('choice_options', array('choiceid'=>$this->_instance)));
$const_cnt = $DB->count_records('choice_options', array('choiceid'=>$this->_instance));
$const_cnt += 1;
} else {
$const_cnt = 1;
}

$consrepeateloptions = array();
$consrepeateloptions['constructoraccessspecifier']['type'] = PARAM_RAW;
$consrepeateloptions['constructorparametertype']['type'] = PARAM_RAW;

$mform->setType('optionid', PARAM_INT);

$this->repeat_elements($constructor, $const_cnt, $consrepeateloptions, 'option_repeats2', 'option_add_fields', 1, null, true);


$mform->addElement( 'header', 'header_method', "Define Methods" );
$method=array();
$method[] = &$mform->createElement('text', 'methodname',get_string('methods',VPL));
$method[] = &$mform->createElement('text', 'methodaccesspecifier',"Enter the modifiers");
$method[] = &$mform->createElement('select', 'methodmodifiers', 'Choose Method Accesspecifier',$options);
$method[] = &$mform->createElement('text', 'methodreturntype',"Enter method returntype");
$method[] = &$mform->createElement('text', 'throwsexcpetion', 'Enter the Exception');
$method[] = &$mform->createElement('text', 'methodannotations',"Enter method Annotations");
print_object("----------------------------------------------------------------------------------------------------");
print_object("count----".$this->_instance);
if ($this->_instance){
print_object("hello---".$this);
$cnt = $DB->count_records('choice_options', array('choiceid'=>$this->_instance));
$cnt += 1;
} else {
$cnt = 1;
}


$repeateloptions1 = array();
$repeateloptions1['methodname']['type'] = PARAM_RAW;
$repeateloptions1['methodaccesspecifier']['type'] = PARAM_RAW;
$repeateloptions1['methodreturntype']['type'] = PARAM_RAW;
$repeateloptions1['throwsexcpetion']['type'] = PARAM_RAW;
$repeateloptions1['methodannotations']['type'] = PARAM_RAW;

$mform->setType('optionid', PARAM_INT);

$this->repeat_elements($method, $cnt, $repeateloptions1, 'option_repeats3', 'option_add_fields', 1, null, true);

 

Attachment repeator.png
Average of ratings: -