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();
}
/**
+++ /dev/null
-function submit_attempts_form(e, args) {
- if (e.target.selectedIndex > 0) {
- submit_form_by_id(null, {id: 'attemptsform'});
- }
-}
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
echo ' ';
- $PAGE->requires->js('mod/choice/choice.js');
$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_attempts_form');
+ $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
echo $OUTPUT->select_menu($selectmenu);
echo '<noscript id="noscriptmenuaction" style="display: inline;">';
echo '<div>';
echo '<a href="javascript:select_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
echo ' ';
- $PAGE->requires->js('mod/scorm/scorm.js');
$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_attempts_form');
+ $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
echo $OUTPUT->select_menu($selectmenu);
echo '<noscript id="noscriptmenuaction" style="display: inline;">';
echo '<div>';
+++ /dev/null
-function submit_attempts_form(e, args) {
- if (e.target.selectedIndex > 0) {
- submit_form_by_id(null, {id: 'attemptsform'});
- }
-}