This is a problem with a question edit form, but may be relevant in a more general context of using Moodle forms, so posting here.
In my REGEXP edit form I want to add a button to display a list of alternate correct answers generated from the regular expressions in the Answers fields. This display would look similar to the "Decode and Verify the question text" in the Cloze question edit form.
I know how to use a registerNoSubmitButton element to trigger a reload of the edit form in order to retrieve the form contents like this:
$mform->addElement('submit', 'showalternate', get_string('showalternate', 'qtype_regexp'));
$mform->registerNoSubmitButton('showalternate');
However, I have quite a lot of validation operations to conduct upon the entered regular expressions (in the Answers fields). Normally these validation operations are conducted upon saving the question, in the usual function validation($data, $files) located in my edit_regexp_form file.
Now, I need the validation function to be called when pressing the "showalternate" button, before I can do anything with the answers data.
But there is a mechanism in the lib/form/submit.php which makes this impossible.
if ($caller->isNoSubmitButton($arg[0])){
//need this to bypass client validation
//for buttons that submit but do not process the
//whole form.
$onClick = $this->getAttribute('onclick');
$skip = 'skipClientValidation = true;';
$onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
$this->updateAttributes(array('onclick'=>$onClick));
};
My question is: is there a way to have another kind of submit-"NoSubmitButton" which would still a) trigger the form validation but b) not save the form?
Joseph