Skip to content

Commit

Permalink
Merge branch 'MDL-71686-311' of https://github.com/marinaglancy/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_311_STABLE
  • Loading branch information
andrewnicols committed Oct 6, 2022
2 parents 459da61 + f533978 commit 27f7c54
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/form/amd/build/dynamicform.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/form/amd/build/dynamicform.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/form/amd/build/modalform.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/form/amd/build/modalform.min.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions lib/form/amd/src/dynamicform.js
Expand Up @@ -136,9 +136,15 @@ export default class DynamicForm {
* @public
*/
load(args = null) {
const formData = new URLSearchParams(Object.entries(args || {}));
const serialize = function(obj, prefix = '') {
return [].concat(...Object.entries(obj).map(([idx, v]) => {
const k = prefix ? prefix + "[" + idx + "]" : idx;
return (typeof v === "object") ? serialize(v, k) : `${k}=${encodeURIComponent(v)}`;
})).join("&");
};
const formData = serialize(args || {});
const pendingPromise = new Pending('core_form/dynamicform:load');
return this.getBody(formData.toString())
return this.getBody(formData)
.then((resp) => this.updateForm(resp))
.then(pendingPromise.resolve);
}
Expand Down
11 changes: 9 additions & 2 deletions lib/form/amd/src/modalform.js
Expand Up @@ -115,15 +115,22 @@ export default class ModalForm {
*/
show() {
const pendingPromise = new Pending('core_form/modalform:init');
const serialize = function(obj, prefix = '') {
return [].concat(...Object.entries(obj).map(([idx, v]) => {
const k = prefix ? prefix + "[" + idx + "]" : idx;
return (typeof v === "object") ? serialize(v, k) : `${k}=${encodeURIComponent(v)}`;
})).join("&");
};

return ModalFactory.create(this.config.modalConfig)
.then((modal) => {
this.modal = modal;

// Retrieve the form and set the modal body. We can not set the body in the modalConfig,
// we need to make sure that the modal already exists when we render the form. Some form elements
// such as date_selector inspect the existing elements on the page to find the highest z-index.
const formParams = new URLSearchParams(Object.entries(this.config.args || {}));
const bodyContent = this.getBody(formParams.toString());
const formParams = serialize(this.config.args || {});
const bodyContent = this.getBody(formParams);
this.modal.setBodyContent(bodyContent);
bodyContent.catch(Notification.exception);

Expand Down

0 comments on commit 27f7c54

Please sign in to comment.