mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Adds ability to pre-fill a form with a complete dataset
This commit is contained in:
parent
1fafaf8577
commit
408ff639dd
@ -240,6 +240,7 @@ function constructDeleteForm(fields, options) {
|
|||||||
* - hidden: Set to true to hide the field
|
* - hidden: Set to true to hide the field
|
||||||
* - icon: font-awesome icon to display before the field
|
* - icon: font-awesome icon to display before the field
|
||||||
* - prefix: Custom HTML prefix to display before the field
|
* - prefix: Custom HTML prefix to display before the field
|
||||||
|
* - data: map of data to fill out field values with
|
||||||
* - focus: Name of field to focus on when modal is displayed
|
* - focus: Name of field to focus on when modal is displayed
|
||||||
* - preventClose: Set to true to prevent form from closing on success
|
* - preventClose: Set to true to prevent form from closing on success
|
||||||
* - onSuccess: callback function when form action is successful
|
* - onSuccess: callback function when form action is successful
|
||||||
@ -263,6 +264,11 @@ function constructForm(url, options) {
|
|||||||
// Default HTTP method
|
// Default HTTP method
|
||||||
options.method = options.method || 'PATCH';
|
options.method = options.method || 'PATCH';
|
||||||
|
|
||||||
|
// Construct an "empty" data object if not provided
|
||||||
|
if (!options.data) {
|
||||||
|
options.data = {};
|
||||||
|
}
|
||||||
|
|
||||||
// Request OPTIONS endpoint from the API
|
// Request OPTIONS endpoint from the API
|
||||||
getApiEndpointOptions(url, function(OPTIONS) {
|
getApiEndpointOptions(url, function(OPTIONS) {
|
||||||
|
|
||||||
@ -346,11 +352,20 @@ function constructFormBody(fields, options) {
|
|||||||
// otherwise *all* fields will be displayed
|
// otherwise *all* fields will be displayed
|
||||||
var displayed_fields = options.fields || fields;
|
var displayed_fields = options.fields || fields;
|
||||||
|
|
||||||
|
// Handle initial data overrides
|
||||||
|
if (options.data) {
|
||||||
|
for (const field in options.data) {
|
||||||
|
|
||||||
|
if (field in fields) {
|
||||||
|
fields[field].value = options.data[field];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Provide each field object with its own name
|
// Provide each field object with its own name
|
||||||
for(field in fields) {
|
for(field in fields) {
|
||||||
fields[field].name = field;
|
fields[field].name = field;
|
||||||
|
|
||||||
|
|
||||||
// If any "instance_filters" are defined for the endpoint, copy them across (overwrite)
|
// If any "instance_filters" are defined for the endpoint, copy them across (overwrite)
|
||||||
if (fields[field].instance_filters) {
|
if (fields[field].instance_filters) {
|
||||||
fields[field].filters = Object.assign(fields[field].filters || {}, fields[field].instance_filters);
|
fields[field].filters = Object.assign(fields[field].filters || {}, fields[field].instance_filters);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user