From a971634639b862571fd3c70f45ebda6710f5226f Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Thu, 12 Dec 2024 12:57:10 -0700 Subject: [PATCH] Autopopulating units field depending on the Fuel Type selected --- .../src/views/OtherUses/AddEditOtherUses.jsx | 12 +++++++ frontend/src/views/OtherUses/_schema.jsx | 31 ++++++++++--------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/frontend/src/views/OtherUses/AddEditOtherUses.jsx b/frontend/src/views/OtherUses/AddEditOtherUses.jsx index 58586cb9e..bbd553ca3 100644 --- a/frontend/src/views/OtherUses/AddEditOtherUses.jsx +++ b/frontend/src/views/OtherUses/AddEditOtherUses.jsx @@ -150,6 +150,18 @@ export const AddEditOtherUses = () => { ) { const ciOfFuel = findCiOfFuel(params.data, optionsData) params.node.setDataValue('ciOfFuel', ciOfFuel) + + // Auto-populate the "Unit" field based on the selected fuel type + if (params.colDef.field === 'fuelType') { + const fuelType = optionsData?.fuelTypes?.find( + (obj) => params.data.fuelType === obj.fuelType + ); + if (fuelType && fuelType.units) { + params.node.setDataValue('units', fuelType.units); + } else { + params.node.setDataValue('units', ''); + } + } } }, [optionsData] diff --git a/frontend/src/views/OtherUses/_schema.jsx b/frontend/src/views/OtherUses/_schema.jsx index a392bfc4a..82e96bd37 100644 --- a/frontend/src/views/OtherUses/_schema.jsx +++ b/frontend/src/views/OtherUses/_schema.jsx @@ -180,21 +180,24 @@ export const otherUsesColDefs = (optionsData, errors) => [ }, { field: 'units', - headerName: i18n.t('otherUses:otherUsesColLabels.units'), - headerComponent: RequiredHeader, - cellEditor: AutocompleteCellEditor, - minWidth: '155', - cellEditorParams: { - options: optionsData.unitsOfMeasure.map((obj) => obj), - multiple: false, - disableCloseOnSelect: false, - freeSolo: false, - openOnFocus: true + headerName: i18n.t('otherUses:units'), + cellEditor: 'agSelectCellEditor', + cellEditorParams: (params) => { + console.log('cellEditorParams: ', params); + const fuelType = optionsData?.fuelTypes?.find( + (obj) => params.data.fuelType === obj.fuelType + ); + const values = fuelType ? [fuelType.units] : []; + return { + values: values + }; }, - suppressKeyboardEvent, - cellRenderer: (params) => - params.value || Select, - cellStyle: (params) => StandardCellErrors(params, errors) + cellRenderer: (params) => { + return params.value ? params.value : Select; + }, + cellStyle: (params) => StandardCellErrors(params, errors), + editable: true, + minWidth: 100 }, { field: 'ciOfFuel',