Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Javascript-interface for repeat elements function

From MoodleDocs

GOAL: improve usability by using dynamic form editing.

 At this moment form editing, especially adding new blank answers, units, choices and fields requires page reloading. 

Editing blanks order or blank removing is not possible without page reloading.

TASK: The main task is development of JavaScript-interface for repeat_elemens function. Other task is make ADD, REMOVE and MOVE actions without page reloading. If JavaScript is not available in user's browser this actions must work with page reloading, like it works now.

 # Where it will be.
  This core patch will work on this pages(default configuration and modules list):
    * Course editing -> Adding a new Choice - Adding fields to form;
    * Course editing -> Adding a new Quiz -  Adding new feedback fields;
    * Course editing -> Editing Quiz-> Editing a calculated question - Adding Blanks for choices;
    * Course editing -> Editing Quiz-> Editing a calculated question - Adding Blanks for Units;
    * Course editing -> Editing Quiz-> Editing a Calculated Multichoice question - Adding Blanks for choices;
    * Course editing -> Editing Quiz-> Editing a Simple Calculated question - Adding Blanks for choices;
    * Course editing -> Editing Quiz-> Editing a Simple Calculated question Adding Blanks for Units;
    * Course editing -> Editing Quiz-> Editing a Matching question - Adding Blanks for choices;
    * Course editing -> Editing Quiz-> Editing a Multiple choice question - Adding Blanks for choices;
    * Course editing -> Editing Quiz-> Editing a Numerical question - Adding Blanks for choices;
    * Course editing -> Editing Quiz-> Editing a Numerical question - Adding Blanks for choices;
    * Course editing -> Editing Quiz-> Adding a short answer question - Adding Blanks for choices;
 This core patch will add new buttons to the form interface.

http://imglink.ru/pictures/21-09-10/f85258328f02d65164e6a15644e5d8a9.jpg [screenshot field]

 # Adding new blanks

Adding new blanks realize by pushing "Add blanks for SMTH" button. It will initiate AJAX request to the server, and will call repeat_elements function and it's result will be displayed on users screen.

3.Removing blanks. It's possible to remove only 'Empty' blanks. Empty blank is that blank, where all key-fields are empty or have default values. List of elements, which will be check: FILE. File upload input box with browse button. Empty, when filepath is empty. FILEPICKER General replacement of file element in Moodle 2.0 . Empty, when filepath is empty. HTMLEDITOR Empty when it doesn't contains eny content. PASSWORD and PASSWORDUNMASK A password element. Empty, when it doesn't contains any text. TEXT Simple text input element. Empty, when it doesn't contains any text. TEXTAREA A textarea element. Empty, when it doesn't contains any text.

Other form elements like DATEPICKER, RECAPTCHA, SELECT, HIDDEN and others can contain's any values, becuse they won't be check.

Blank's removing realize by pushind remove button(see screenshot) and confirming your choise. If blank's removing isn't possible user will get allert with reason. [screenshot remove button] 4.Moving blanks Blanks moving is available by dragging them with move button [screenshot move button] At any moment you can set all your blanks in default positions, using button "Restore order"


Adding new blank answer requires page-reloading. It's not comfortable. Using advanced opportunities of YUI library we can realize adding blank choices without it. Button "Blanks for 3 more Choices" will be changed to "Add blank choise".

Pushing button Add blank choise will add one empty answer to the page without reloading.

Another addition is removing answers from page withou reloading. Removing answer will be able, if all text fields(input text or textarea) are empty. Pushing button http://imglink.ru/pictures/21-09-10/36894a2cd789d3916c86f12105b96d42.jpg while all text fields are empty will ask confirmation using confirm dialog. http://imglink.ru/pictures/21-09-10/68342df9db64b00f69b4dcd15edba37f.jpg If text fields are not empty, like here http://imglink.ru/pictures/21-09-10/797d7f513ce2c3588e4be3e216f4b767.jpg you will see alert dialog http://imglink.ru/pictures/21-09-10/166ccbfe86c3f9d14d7c8b2aef88bbdb.jpg

Another addition is moving answers up and down in answer list, using this button:http://imglink.ru/pictures/21-09-10/caa63175d62020a04104cb2fdf1f789a.jpg