MDL-19756 Refactored JS code from SCORM and choice modules into the core function submit_form_by_id()

This commit is contained in:
nicolasconnault 2009-07-28 11:24:57 +00:00
parent a19f419db2
commit dc58020794
5 changed files with 27 additions and 19 deletions

View file

@ -205,17 +205,37 @@ function lockoptionsallsetup(formid) {
return lockoptionsall(formid);
}
function submit_form_by_id(e, args) {
/**
* Helper function mainly for drop-down menus' onchange events,
* submits the form designated by args.id. If args.selectid is also
* given, it only submits the form if the selected <option> is not
* the first one (usually the "Choose..." option)
* Example usage of the moodle_select_menu component with this function:
* <pre>
* $selectmenu = new moodle_select_menu();
* $selectmenu->options = array('delete' => get_string('delete'));
* $selectmenu->name = 'action';
* $selectmenu->button->label = get_string('withselected', 'quiz');
* $selectmenu->id = 'menuaction';
* $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
* echo $OUTPUT->select_menu($selectmenu);
* </pre>
*/
function submit_form_by_id(e, args) {
var theform = document.getElementById(args.id);
if(!theform) {
if (!theform) {
return false;
}
if(theform.tagName.toLowerCase() != 'form') {
if (theform.tagName.toLowerCase() != 'form') {
return false;
}
if(!theform.onsubmit || theform.onsubmit()) {
return theform.submit();
if (args.selectid) {
var select = document.getElementById(args.selectid);
if (select.selectedIndex == 0) {
return false;
}
}
return theform.submit();
}
/**