![]() The ModalForm class listens to the click events on no-submit buttons, if such button is pressed, the new request is sent to the same web service and the form is re-rendered, client-side validation is not called in this case (example: adding a repeated element).The form itself is then displayed inside the popup. This web service creates a new instance of the form (specified in the formClass parameter), passes the arguments (args parameter), and returns the form HTML and JS similar to how Fragment does it. When an instance of the ModalForm class is created in the Javascript, the AJAX requests calls the web service core_form_dynamic_form.After that you can call load() as many times as necessary Import ModalForm from 'core_form/modalform' import ) Įrror to avoid: Make sure that you initialize the form only once on the page. Optionally listen to other events, for example, you may wish to add "Are you sure?" dialogue before the form is cancelled or submittedĮxample of modal form initialization in the Javascript.The event listener in the JS will receive everything that dynamic_form::process_dynamic_submission() returned in PHP. Add listener to _SUBMITTED event that performs some action when the form is submitted (display notification, redirect, refresh part of the page, etc). ![]() Initialize the form in the listener to some javascript event (for example, a click on the "Add" or "Edit" link) show the form.In PHP: Create a class with the form definition extending \core_form\dynamic_form, do not add submit/cancel buttons to the form definition.To display a moodleform in a modal popup you need to: 2.2 Example of a dynamically loaded form.2.1 Example of a pre-rendered form with AJAX submission.1.1 Example of modal form initialization in the Javascript.
0 Comments
Leave a Reply. |