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..9af82de0b 100644 --- a/frontend/src/views/OtherUses/_schema.jsx +++ b/frontend/src/views/OtherUses/_schema.jsx @@ -181,20 +181,22 @@ 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 + cellEditor: 'agSelectCellEditor', + 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',