MDL-71686 forms: allow arrays in dynamic forms args
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -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);
|
||||
}
|
||||
|
||||
@@ -115,6 +115,13 @@ 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;
|
||||
@@ -122,8 +129,8 @@ export default class ModalForm {
|
||||
// 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user