Initial data of the instance.
Optional
crudCRUD instance for this API. Used for API submission (create or update).
Optional
dataAPI model raw data.
Readonly
dataTriggers when the form data is changed.
API errors.
Readonly
errorTriggers when the form errors update.
Optional
errorAPI error status.
Form group data for this object.
Optional
idAPI model ID. If not set, means form is for creation and not edition.
Whether this form is dirty.
It is only used when ReactiveForm.useDirtyAsPayload
is true
.
API loading indicator.
For these control names, use whole object as control value instead of ID only. (default is []).
Readonly
onTriggers when the form is reset.
Readonly
payloadPayload 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 }
In 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
Readonly
subscriptionsStore 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.
API success indicator.
Update ReactiveForm.data after API call success.
Update ReactiveForm.id after creation API call success.
Use ReactiveForm.dirtyValue for payload.
UI view mode indicator.
Readonly
viewTriggers 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
Readonly
TEXTTexts used for UI. You can change these for preference or translation.
Is this form for creation of model?
Is this form for update of model?
reactive form value (ignore ReactiveForm.getPayload and ReactiveForm.dirtyValue).
Alias for FormGroup.valueChanges.
Clear out all errors.
Trigger errorChange (default is true)
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.
const getPayload = (): Dict => {
let payload: Dict = Object.assign({}, this.value);
if (form.removeEmptyValuesFromPayload) {
payload = removeEmptyValuesFromDict(
payload,
form.removeEmptyArraysFromPayload\
);
}
if (form.useDirtyAsPayload) {
payload = form.dirtyValue;
}
for (const pipe of form.payloadPipes) {
payload = pipe(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).
Whether to trigger valueChanges for the form control (default is false).
Set the ReactiveForm.id to the form from the data (default is true).
Set the ReactiveForm.data to the form to the data (default is true).
Reset all dirty controls (default is true).
Reset the reactive form to empty state.
Clear form ID (default is false).
Clear form data (default is false).
Restore reactive form data from form data (default is true).
Use ReactiveForm.patch and use the original data from ReactiveForm.data.
Whether to trigger valueChanges for the form (default is false).
Set the form to edit mode or view mode.
Useful for the UI to edit or cancel edit.
True to set to edit mode.
Invoke restoreForm if status is false (default is true). Good for canceling the form to previous state.
Triggers 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.