Skip to content

Commit 2a86509

Browse files
committed
Send live action arguments to backend
1 parent 39d4e49 commit 2a86509

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ class default_1 extends Controller {
10701070
directives.forEach((directive) => {
10711071
const _executeAction = () => {
10721072
this._clearWaitingDebouncedRenders();
1073-
this._makeRequest(directive.action);
1073+
this._makeRequest(directive.action, directive.args.length > 0 ? directive.args : directive.named);
10741074
};
10751075
let handled = false;
10761076
directive.modifiers.forEach((modifier) => {
@@ -1162,11 +1162,23 @@ class default_1 extends Controller {
11621162
}, this.debounceValue || DEFAULT_DEBOUNCE);
11631163
}
11641164
}
1165-
_makeRequest(action) {
1165+
_makeRequest(action, values) {
11661166
const splitUrl = this.urlValue.split('?');
11671167
let [url] = splitUrl;
11681168
const [, queryString] = splitUrl;
11691169
const params = new URLSearchParams(queryString || '');
1170+
let valueParams = null;
1171+
if (Array.isArray(values)) {
1172+
valueParams = new URLSearchParams();
1173+
values.forEach((v, i) => valueParams.set(i, v));
1174+
}
1175+
else if (typeof values === 'object' && Object.keys(values).length > 0) {
1176+
valueParams = new URLSearchParams();
1177+
Object.keys(values).forEach(k => valueParams.set(k, values[k]));
1178+
}
1179+
if (valueParams !== null) {
1180+
params.set('values', valueParams.toString());
1181+
}
11701182
const fetchOptions = {};
11711183
fetchOptions.headers = {
11721184
'Accept': 'application/vnd.live-component+json',

src/LiveComponent/assets/src/live_controller.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export default class extends Controller {
144144
// taking precedence
145145
this._clearWaitingDebouncedRenders();
146146

147-
this._makeRequest(directive.action);
147+
this._makeRequest(directive.action, directive.args.length > 0 ? directive.args : directive.named);
148148
}
149149

150150
let handled = false;
@@ -296,11 +296,26 @@ export default class extends Controller {
296296
}
297297
}
298298

299-
_makeRequest(action: string|null) {
299+
_makeRequest(action: string|null, values: Array<string>|object) {
300300
const splitUrl = this.urlValue.split('?');
301301
let [url] = splitUrl
302302
const [, queryString] = splitUrl;
303303
const params = new URLSearchParams(queryString || '');
304+
let valueParams = null;
305+
306+
if (Array.isArray(values)) {
307+
valueParams = new URLSearchParams();
308+
309+
values.forEach((v, i) => valueParams.set(i, v));
310+
} else if (typeof values === 'object' && Object.keys(values).length > 0) {
311+
valueParams = new URLSearchParams();
312+
313+
Object.keys(values).forEach(k => valueParams.set(k, values[k]));
314+
}
315+
316+
if (valueParams !== null) {
317+
params.set('values', valueParams.toString());
318+
}
304319

305320
const fetchOptions: RequestInit = {};
306321
fetchOptions.headers = {

0 commit comments

Comments
 (0)