Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-59740

Allow submit buttons other than 'cancel' to be secondary

XMLWordPrintable

    • MOODLE_32_STABLE
    • MOODLE_32_STABLE, MOODLE_33_STABLE
    • MDL-59740_master
    • Hide
      1. Put the following code into a .php file and place it in your wwwroot.

        <?php
         
        require_once('config.php');
        require_once($CFG->libdir . '/formslib.php');
         
        $PAGE->set_context(context_system::instance());
        $PAGE->set_url('/');
         
        class test_form extends moodleform {
         
            public function definition() {
                $mform =& $this->_form;
         
                $mform->addElement('submit', '1', 'Should be primary');
                $mform->addElement('submit', 'cancel', 'Should be secondary');
                $mform->addElement('submit', 'cancel', 'Should be primary', array(), true);
                $mform->addElement('submit', 'cancel', 'Should be secondary', array(), false);
                $mform->addElement('submit', 'boo', 'Should be secondary', array(), false);
                $mform->addElement('submit', 'boo1', 'Should be primary', array(), true);
            }
        }
         
        $a = new test_form();
         
        echo $OUTPUT->header();
        echo $a->display();
        echo $OUTPUT->footer();
        

      2. Confirm the buttons are styled the way their name suggests.
      Show
      Put the following code into a .php file and place it in your wwwroot. <?php   require_once('config.php'); require_once($CFG->libdir . '/formslib.php');   $PAGE->set_context(context_system::instance()); $PAGE->set_url('/');   class test_form extends moodleform {   public function definition() { $mform =& $this->_form;   $mform->addElement('submit', '1', 'Should be primary'); $mform->addElement('submit', 'cancel', 'Should be secondary'); $mform->addElement('submit', 'cancel', 'Should be primary', array(), true); $mform->addElement('submit', 'cancel', 'Should be secondary', array(), false); $mform->addElement('submit', 'boo', 'Should be secondary', array(), false); $mform->addElement('submit', 'boo1', 'Should be primary', array(), true); } }   $a = new test_form();   echo $OUTPUT->header(); echo $a->display(); echo $OUTPUT->footer(); Confirm the buttons are styled the way their name suggests.

      There is a hardcoded check that only sets 'cancel' submit buttons in mforms as 'btn-secondary'. This is not good as there are places in Moodle where we have multiple primary buttons on a form (example adding an activity). This is also bad for third party developers, who may have multiple submit buttons, which all appear as primary making the form look unattractive and confusing. We can not assume only 'cancel' will be the secondary button.

            markn Mark Nelson
            markn Mark Nelson
            cameron1729 cameron1729
            Jun Pataleta Jun Pataleta
            David Monllaó David Monllaó
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.