Note:

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

Fragment

From MoodleDocs
Revision as of 07:20, 3 May 2016 by Adrian Greeve (talk | contribs) (Initial bare details)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introduction

fragment.js is an Asynchronous Module Definition (AMD) module to allow the inclusion of rendered HTML code and associated JavaScript to be inserted through AJAX onto a page.

History

The issue for this was created to allow Moodle mforms to be changed and submitted via AJAX. Mforms currently do a lot of validation, and include accessibility code and tags. Most of Moodle uses these forms and there seemed no clear way to borrow or create another system that would satisfy all requirements.

fragment.js details

This JavaScript module is located at lib/amd/src/fragment.js

loadFragment is the exposed function to use. It takes four parameters.

  • component: The component for the callback that you will also supply. e.g. "mod_assign"
  • callback: The callback that you are calling.
  • contextid: The context ID for the component.
  • params: Parameters for the callback function.

This function returns a promise that is resolved with HTML and JavaScript.

Callback