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

Control over which button is used when a user presses enter in a form



    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.6.1
    • None
    • Forms Library, JavaScript


      This comes from MDL-33653 and https://moodle.org/mod/forum/discuss.php?d=255651#p1109004

      To see the problem, edit an existing Multiple choice question, put keyboard focus in the Question name field and press enter. The form reloads, because the form gets submitted as if the 'Add blanks for three more choices' button was pressed.

      And, now I think about it some more, I remember that what happens on a form with multiple buttons when you press enter is not well defined. I think the behaviour is:

      • IE and Chrome always behave as if the first button in the form was pressed.
      • Firefox behaves as if the next button in the form, after the one where keyboard focus was pressed.

      To get consistent behaviour (which woudl be a small but useful usability improvement) I think we need to add a bit of JavaScript that handles Key press: Enter exactly how we want. Specifically:

      1. New form class method $this->set_defualt_button($name); so that a given form can specify exactly what it wants.
      2. Heursitic for when this is not called:
        • If add_action_buttons is used, then make the first button it adds the default
        • Otherwise make the first button in the form, which is no a 'registerNoSubmitButton', the one.
      3. JavaScript code that intercepts keypress:enter, and make it click the given button, rather that submitting the form which picks a button at random as described above.
        I think this is a worthwhile usability improvement, so I will file it in the tracker.


        Issue Links



              Unassigned Unassigned
              timhunt Tim Hunt
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Sujith Haridasan, Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Stevani Andolo
              1 Vote for this issue
              4 Start watching this issue