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?