Skip to content

Commit 04c21be

Browse files
committed
fix: prevent empty fields in string columns when acceptsEmptyFields option is disabled
1 parent 2614214 commit 04c21be

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/inputs/Table/ColumnTypes.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ const _editModeSetter = (params) => {
1212
return true;
1313
};
1414

15+
const _stringSetter = (params) => {
16+
let newValue = params.newValue?.trim() ?? '';
17+
const unauthorizedEmptyField = newValue.length === 0 && !params.colDef.cellEditorParams?.acceptsEmptyFields;
18+
19+
if (!params.context.editMode || unauthorizedEmptyField) {
20+
newValue = params.oldValue;
21+
}
22+
23+
params.data[params.colDef.field] = newValue;
24+
return true;
25+
};
26+
1527
const _boolSetter = (params) => {
1628
let newValue = params.newValue?.toLowerCase() ?? '';
1729
const allowedEmptyField = params.colDef.cellEditorParams?.acceptsEmptyFields && newValue.length === 0;
@@ -160,7 +172,7 @@ export const getColumnTypes = (dateFormat) => {
160172
nonEditable: { editable: false },
161173
nonResizable: { resizable: false },
162174
nonSortable: { sortable: false },
163-
string: {}, // No specific behavior here, but required to prevent ag-grid warning
175+
string: { valueSetter: _stringSetter },
164176
bool: {
165177
valueSetter: _boolSetter,
166178
},

0 commit comments

Comments
 (0)