## General developer forum

### Repeat form elements - _instance??

Repeat form elements - _instance??

The dev docs for repeat form elements (http://docs.moodle.org/dev/lib/formslib.php_repeat_elements) has a bit thus...

if ($this->_instance){$repeatno=count_records('choice_options', 'choiceid', $this->_instance);$repeatno += 2;} else {    $repeatno = 5;}Question is... what is$this->_instance?  I can't find any other reference to it...

Average of ratings: -
Re: Repeat form elements - _instance??

I think that sample code comes from mod/choice/modform.php, where ->_instance is defined.

the effect of that code is, if you are editing an existing choice, you get one repeat for each choice defined so far, plus space for two more. If you are creating a new choice, you get 5 repeats.

Actually, in the question forms, we eventually worked out that the +2 thing is more often a pain, and a waste of space, than it is a help. It is better to show exactly the right number of repeats when you are editing an existing thing. If people really want more, they have to click the button, but it is much more common that people are editing an existing thing, and don't want extra blanks.

Average of ratings: Useful (1)
Re: Repeat form elements - _instance??

Ok thanks. I was just checking if anything was defined in my database table for these fields but I wondered if I was missing a trick somewhere

Average of ratings: -