Skip to content

Commit

Permalink
fix: prevent empty fields in string columns when acceptsEmptyFields o…
Browse files Browse the repository at this point in the history
…ption is disabled
  • Loading branch information
csm-thu committed Jun 23, 2023
1 parent 2614214 commit 04c21be
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/inputs/Table/ColumnTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ const _editModeSetter = (params) => {
return true;
};

const _stringSetter = (params) => {
let newValue = params.newValue?.trim() ?? '';
const unauthorizedEmptyField = newValue.length === 0 && !params.colDef.cellEditorParams?.acceptsEmptyFields;

if (!params.context.editMode || unauthorizedEmptyField) {
newValue = params.oldValue;
}

params.data[params.colDef.field] = newValue;
return true;
};

const _boolSetter = (params) => {
let newValue = params.newValue?.toLowerCase() ?? '';
const allowedEmptyField = params.colDef.cellEditorParams?.acceptsEmptyFields && newValue.length === 0;
Expand Down Expand Up @@ -160,7 +172,7 @@ export const getColumnTypes = (dateFormat) => {
nonEditable: { editable: false },
nonResizable: { resizable: false },
nonSortable: { sortable: false },
string: {}, // No specific behavior here, but required to prevent ag-grid warning
string: { valueSetter: _stringSetter },
bool: {
valueSetter: _boolSetter,
},
Expand Down

0 comments on commit 04c21be

Please sign in to comment.