Data of the form (API object interface).
Initial data of the instance.
ReadonlycrudCRUD instance for this API. Used for API submission (create or update).
ReadonlydataAPI model raw data.
ReadonlydataTriggers when the form data is changed.
ReadonlyerrorAPI errors.
ReadonlyerrorTriggers when the form errors update.
ReadonlyerrorAPI error status.
ReadonlyformForm group data for this object.
ReadonlyidAPI object ID. If not set, means form is for creation and not edition.
ReadonlyisWhether form is in create mode.
Whether this form is dirty.
It is only used when ReactiveForm.useDirtyAsPayload
is true.
ReadonlyloadingAPI loading indicator.
ReadonlynoFor these control names, use whole object as control value instead of ID only. (default is []).
ReadonlyonTriggers when the form is reset.
ReadonlypayloadPayload is passed through these methods to be used for final output of ReactiveForm.getPayload.
Do not call ReactiveForm.getPayload inside pipe functions to prevent infinite loops.
const pipeA = (form: ReactiveForm<Foo>, payload: Dict): Dict => {
payload.a = Number(payload.a);
return payload;
};
const pipeB = (form: ReactiveForm<Foo>, payload: Dict): Dict => {
payload.b = Number(payload.b);
return payload;
};
const form = new ReactiveForm<Foo>({
payloadPipes: [pipeA, pipeB],
// Other stuff
});
form.value; // { a: "1", b: "2" }
form.getPayload(); // { a: 1, b: 2 }
ReadonlypreviousIn case of ReactiveForm.useDirtyAsPayload when doing patch, the form value is stored here (no reference) and the dirty value will compare the form value to this value to return the modified (dirty) changes.
For resetting dirty status, you can call ().
It is not recommended to touch this property but in a rare scenario where dirty value is not working as expected, you can modify this value to let this class know this is the actual previous value.
Protected ReadonlysubscriptionsStore subscriptions from constructor and unsubscribe from them by invoking ReactiveForm.destroy method.
Will be used in case of ReactiveForm.useDirtyAsPayload and then the ReactiveForm.destroy invoke is required to unsubscribe.
ReadonlysuccessAPI success indicator.
ReadonlyupdateUpdate ReactiveForm.data after API call success.
ReadonlyupdateUpdate ReactiveForm.id after creation API call success.
Use ReactiveForm.dirtyValue for payload.
ReadonlyviewUI view mode indicator.
ReadonlyviewTriggers when form goes to edit mode or view mode only when using setEditStatus.
You can manually trigger this if you don't use the method mentioned above.
Static ReadonlyTEXTTexts used for UI. You can change these for preference or translation.
payload but include only changed values.
reactive form value (ignore ReactiveForm.getPayload and ReactiveForm.dirtyValue).
Alias for FormGroup.valueChanges.
Update error for a single control.
Name of the control to update error for.
Array of error strings.
Get form value (payload) based on given parameters for manipulation. Override the value of this method for custom payload handling.
Default value of this method is this code below, you can use it for custom modification if initial variables and pipes are not enough.
let payload: Dict = Object.assign({}, this.value);
if (this.useDirtyAsPayload()) {
payload = this.dirtyValue;
}
for (const pipe of this.payloadPipes()) {
payload = pipe(this, payload);
}
return payload;
Update a form value with given data. Supports dict values as well. Used to update form group from a retrieve API call data.
For object values, it stores their "id" instead of the whole object. For array values, it stores list of "id"s instead of the entire objects.
You want to call this when you get the response from the API to populate the form with the data.
Data to patch to the form (usually comes from API response).
Optionalemit: boolean = falseWhether to trigger valueChanges for the form control
OptionalsetId: boolean = trueSet the ReactiveForm.id to the form from the data
OptionalsetData: boolean = trueSet the ReactiveForm.data to the form to the data
OptionalresetDirty: boolean = trueReset all dirty controls
Reset the reactive form to empty state.
Optionalid: boolean = falseClear form ID
Optionaldata: boolean = falseClear form data
OptionalrestoreFromData: boolean = trueRestore reactive form data from form data
Use ReactiveForm.patch and use the original data from ReactiveForm.data.
Optionalemit: boolean = falseWhether to trigger valueChanges for the form control
OptionalsetId: boolean = trueSet the ReactiveForm.id to the form from the data
OptionalsetData: boolean = trueSet the ReactiveForm.data to the form to the data
OptionalresetDirty: boolean = trueReset all dirty controls
Set the form to edit mode or view mode.
Useful for the UI to edit or cancel edit.
Optionalstatus: boolean = trueTrue to set to edit mode.
Optionalrestore: boolean = trueInvoke restoreForm if status is false. Good for canceling the form to previous state.
Method used to catch error from submission.
Handles:
loadingsuccesserrorTriggers ReactiveForm.validateControls and if any error found
the error.detail will be set.
whether form contains any error.
Sets error for each invalid control in the form just like the DRF error ApiError.
Used to validate and show errors for inputs before making an API call.
Also used in ReactiveForm.validate.
Django Rest Framework CRUD ModelViewSet endpoint form builder class.
T is for type of the data of the form (API object interface). CT is for type of the data of the Crud. CTL is for the type of the data of the Crud in list method.
Type Param: CT
Data of the Crud.
Type Param: CTL
Data of the Crud in list method.