New forms library

New forms library

by Adrian Greeve -
Number of replies: 4
Picture of Core developers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers

We are going to create a new forms library for Moodle.

I have created a devpad page for general discussion and ideas as to how to proceed with this project. 

All information and discussion will happen on devpad (the link mentioned below) for one week before we start work on a specification. 

If you would like to have some input as to how the new forms lib will be implemented then please go to https://devpad.moodle.org/p/new_forms_lib and join the conversation.

Average of ratings: Useful (2)
In reply to Adrian Greeve

Re: New forms library

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Not that Moodle does not just use QuickForms. We already have our own form API class moodleform. Internally uses HTMLQuickForm for some stuff, but for other Moodle code, the QuickForms API is only partially exposed.

We should definitely get rid of QuickForms internally.

We should not change the API that existing Moodle code uses to create forms if at all possible. That would create huge amounts of work for many people.

(Has anyone tried to count how many forms are defined in Moodle core, and in all the plugins in the plugins DB? That would be useful data that might inform this the design decisions we need to make. Might also be interesting to count how often each element type is used in Moodle code. Also, how often features like repeat_elements, groups of fields, defintion_after_data, hard_freeze, etc. are used. Can anyone conjure up the necessary regular-expression magic to do this?)

So, what should we do. When this has been discussed at hack-fests in the past (which has happened several times over many years) the discussion has normally suggested a plan something like this:

  1. Change the moodleform internals, so that when a form is displayed, that is done entirely with Moodle rendering code (that is, templates) not QuickForms.
  2. Change the moodleform internals, so that when the form is submitted, and we need to validate then get the values out, that is done without any remaining QuickForms stuff. (I think quite a lot of this skips QuickForms already.)
  3. Change how the moodleform class represents the structure of the form internally, so that the objects for each element are no longer based on the QuickForms classes.
  4. At this point, QuickForms is gone.
  5. Work out a JSON format for the form data, so that the structure of a form can be sent to JavaScript, and make code to export a form in that structure.
  6. Write the JS code that takes that JSON and displays the form.

(2. & 3. might need to be combined. It could well be possible to work on 5. & 6. in parallel to 1. to 3.)

This approach is incremental, and is the best chance of preserving most backwards-compatibility. We will probably be forced to break a few complex and rare things, e.g. people who have defined their own element types.

I also recommend that you look at some of the more complex forms in Moodle. Places I know complexity lies:

  • The edit question forms
  • The course settings form
  • Activity settings forms for the more complex activities (forum, assignment, workshop, quiz, ...)

Average of ratings: Useful (2)
In reply to Tim Hunt

Re: New forms library

by Dan Poltawski -
We should not change the API that existing Moodle code uses to create forms if at all possible. That would create huge amounts of work for many people.

I would refine that to be - we should have a backwards compatibility layer which continues to work indefinitely with the existing API.

I don't think you should be constrained for the new ways of creating/improving forms having to follow this (relatively horrible) api. 

Previous discussions: I can remember which should be re-read (i'm sure there are more, this is a hot potato of Moodle development for as long as I can remember):

https://docs.moodle.org/dev/Perth_Hackfest_October_2012/Forms_API

https://moodle.org/mod/forum/discuss.php?d=200124

https://moodle.org/mod/forum/discuss.php?d=211454

Offtopic rant: Why do people prefer etherpads, or wiki talk pages for discussions? They are terrible for threaded asycronous discussion.

Average of ratings: Useful (4)
In reply to Adrian Greeve

Re: New forms library

by Adrian Greeve -
Picture of Core developers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers

Thanks everyone for joining in on this conversation. Your input has been most valuable. We have created an epic for this issue (MDL-52143). Feel free to continue to make comments there. 


We will now start writing up the specification. Once a specification has been complete, I will create another post in the new features forum.

In reply to Adrian Greeve

Re: New forms library

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Who did join in the conversation? How much discussion was there?

Let's at least copy-and-paste the summary of the Etherpad document here:

Summation of this document

    
  • Backwards compatibility is an important thing and we shouldn't try to replace mforms. Most people agree that just a simple update to mforms to make it php7 compliant is the way to proceed.
  • Mforms are used extensively throughout Moodle.
  • There are a few places around moodle that do not use mforms and it would be nice to have all areas covered by a library of some sort.
  • Previous discussion about forms from the hackfest should be considered.
  • HTML 5 validation could be used where appropriate.
  • The introduction of AJAX to JavaScript forms seems popular.
  • Some talk of using existing frameworks.
  • Symphony
  • Drupal
  • JavaScript form validation libraries.
  • Separation of display and validation
  • People aren't happy with using devpad as a medium to discuss projects such as this one.
  • Potential to improve form design.
  • A few ideas / code on how we could implement a JavaScript form library.