Skip to content

Commit c5d0b03

Browse files
committed
add button action "setExtraData"
1 parent ddcbfd1 commit c5d0b03

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

assets/tag-attributes.pegjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ Function
112112
= 'setFieldValue' _ '(' _ target:PATH _ ',' _ source:SOURCEARG _ ')' {
113113
return {_funcName: 'setFieldValue', _funcArgs: [target.split('.'), source]};
114114
}
115+
/ 'setExtraData' _ '(' _ target:PATH _ ',' _ source:SOURCEARG _ ')' {
116+
return {_funcName: 'setExtraData', _funcArgs: [target.split('.'), source]};
117+
}
115118
/ 'deletePartial' _ '(' _ target:PATH _ ',' _ source:SOURCEARG _ ')' {
116119
return {_funcName: 'deletePartial', _funcArgs: [target.split('.'), source]};
117120
}

client/django-formset/DjangoFormset.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,17 @@ class DjangoButton {
946946
}
947947
}
948948

949+
/**
950+
* Transfer value from one element to another one.
951+
*/
952+
//@allowedAction
953+
private setExtraData(target: Path, source: FieldValue) {
954+
return (response: Response) => {
955+
this.formset.setExtraData(target, source);
956+
return Promise.resolve(response);
957+
}
958+
}
959+
949960
//@allowedAction
950961
private deletePartial(target: Path, source: FieldValue) {
951962
return (response: Response) => {
@@ -2327,6 +2338,10 @@ export class DjangoFormset implements DjangoFormset {
23272338
}
23282339
}
23292340

2341+
public setExtraData(path: Path, value: any) {
2342+
setDataValue(this.extraData, path, value);
2343+
}
2344+
23302345
public findFirstErrorReport() : Element|null {
23312346
for (const form of this.forms) {
23322347
const errorReportElement = form.findFirstErrorReport();

docs/source/buttons.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ as queued actions for buttons in **django-formset**:
100100
the latter case that value is transferred to the target field.
101101
By prefixing the source value with a ``^`` caret, the value is taken from a response object
102102
fetched by a previous request.
103+
* ``setExtraData(path.to.target, source_value)`` sets a value to be submitted as extra data along
104+
with the form data. The target path specifies where to store that value inside the extra data
105+
object. The source value can be a string, number or a boolean. By prefixing the source value with
106+
a ``^`` caret, the value is taken from a response object fetched by a previous request.
103107
* ``emit("event name")`` emit a named event to the DOM.
104108
* ``clearErrors`` clears all error annotations from a previously failed form validation.
105109
* ``activate`` activates the button to be intercepted by another component, for instance in

0 commit comments

Comments
 (0)