mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 21:00:45 +00:00
Add otherValues to form field possibleValues and queryString based on record values in widget load
This commit is contained in:
@ -75,7 +75,7 @@ function QFMDBridgeForm({fields, record, handleChange, handleSubmit}: QFMDBridge
|
|||||||
initialValues[field.name] = record.values.get(field.name);
|
initialValues[field.name] = record.values.get(field.name);
|
||||||
}
|
}
|
||||||
const [lastValues, setLastValues] = useState(initialValues);
|
const [lastValues, setLastValues] = useState(initialValues);
|
||||||
const [loaded, setLoaded] = useState(false)
|
const [loaded, setLoaded] = useState(false);
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
@ -102,7 +102,7 @@ function QFMDBridgeForm({fields, record, handleChange, handleSubmit}: QFMDBridge
|
|||||||
|
|
||||||
if (!loaded)
|
if (!loaded)
|
||||||
{
|
{
|
||||||
return (<div>Loading...</div>);
|
return (<Box py={"1rem"}>Loading...</Box>);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -111,6 +111,18 @@ function QFMDBridgeForm({fields, record, handleChange, handleSubmit}: QFMDBridge
|
|||||||
} = DynamicFormUtils.getFormData(fields);
|
} = DynamicFormUtils.getFormData(fields);
|
||||||
DynamicFormUtils.addPossibleValueProps(dynamicFormFields, fields, null, null, record ? record.displayValues : new Map());
|
DynamicFormUtils.addPossibleValueProps(dynamicFormFields, fields, null, null, record ? record.displayValues : new Map());
|
||||||
|
|
||||||
|
const otherValuesMap = new Map<string, any>();
|
||||||
|
record.values.forEach((value, key) => otherValuesMap.set(key, value));
|
||||||
|
|
||||||
|
for (let fieldName in dynamicFormFields)
|
||||||
|
{
|
||||||
|
const dynamicFormField = dynamicFormFields[fieldName];
|
||||||
|
if (dynamicFormField.possibleValueProps)
|
||||||
|
{
|
||||||
|
dynamicFormField.possibleValueProps.otherValues = otherValuesMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// re-introduce these two context providers, in case the child calls this //
|
// re-introduce these two context providers, in case the child calls this //
|
||||||
// method under a different root... maybe this should be optional per a param? //
|
// method under a different root... maybe this should be optional per a param? //
|
||||||
@ -190,8 +202,14 @@ function QFMDBridgeWidget({widgetName, tableName, record, entityPrimaryKey, acti
|
|||||||
const qController = Client.getInstance();
|
const qController = Client.getInstance();
|
||||||
const qInstance = await qController.loadMetaData();
|
const qInstance = await qController.loadMetaData();
|
||||||
|
|
||||||
|
const queryStringParts: string[] = [];
|
||||||
|
for (let key of record?.values?.keys())
|
||||||
|
{
|
||||||
|
queryStringParts.push(`${encodeURIComponent(key)}=${encodeURIComponent(record.values.get(key))}`);
|
||||||
|
}
|
||||||
|
|
||||||
setWidgetMetaData(qInstance.widgets.get(widgetName));
|
setWidgetMetaData(qInstance.widgets.get(widgetName));
|
||||||
setWidgetData(await qController.widget(widgetName, null)); // todo queryParams... ?
|
setWidgetData(await qController.widget(widgetName, queryStringParts.join("&")));
|
||||||
|
|
||||||
setReady(true);
|
setReady(true);
|
||||||
})();
|
})();
|
||||||
@ -199,7 +217,7 @@ function QFMDBridgeWidget({widgetName, tableName, record, entityPrimaryKey, acti
|
|||||||
|
|
||||||
if (!ready)
|
if (!ready)
|
||||||
{
|
{
|
||||||
return (<div>Loading...</div>);
|
return (<Box py={"1rem"}>Loading...</Box>);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user