I'm using the repeat_elements function (https://docs.moodle.org/dev/lib/formslib.php_repeat_elements) to create interactive fields in a plugin I'm developing. It works well both for letting the user add groups of fields as needed and data processing.
The problem is that I cannot find a way to remove these elements if the user wants to, using the same logic, with a button in the form interface. I can create a submit button element and add it to the repeated elements but am not sure where to go from there.
This button would need to cancel client validation I assume, reload the updated page with the element the user wanted gone removed and all the fields kept at their current state. Repeated element indexing would need to be updated as well.
Is there a quick and easy way to do this with built in Moodle functions or do I need to build something from the ground up for this?
I found what I was looking for with registerNoSubmitButton() which does exactly what I was after.
Hi, David Poly.
I'm trying to do something very similar to what you''ve done.
How did you implemented it ?
An example of my code :
$this->questions = $mform->createElement('button', 'deletequestion', get_string('question_remove', 'mod_mymod'), 0);
-- end Code
I just want to remove 'question's created with the 'Add' button implemented by 'repeat_elements' method.