Skip to content

Commit cfe050b

Browse files
committed
fix: allow string and decimal-like objects in setFieldValue method
1 parent d756ee5 commit cfe050b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

adminforth/dataConnectors/baseConnector.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
252252
if (value === "" || value === null) {
253253
return this.setFieldValue(field, null);
254254
}
255+
// Accept string
255256
if (typeof value === "string") {
256257
const string = value.trim();
257258
if (!string) {
@@ -262,6 +263,13 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
262263
}
263264
throw new Error(`Value is not a decimal. Field ${field.name} with type is ${field.type}, but got value: ${value} with type ${typeof value}`);
264265
}
266+
// Accept Decimal-like objects (e.g., decimal.js) by using toString()
267+
if (value && typeof value === "object" && typeof (value as any).toString === "function") {
268+
const s = (value as any).toString();
269+
if (typeof s === "string" && s.trim() !== "" && Number.isFinite(Number(s))) {
270+
return this.setFieldValue(field, s);
271+
}
272+
}
265273

266274
throw new Error(`Value is not a decimal. Field ${field.name} with type is ${field.type}, but got value: ${String(value)} with type ${typeof value}`);
267275
}

0 commit comments

Comments
 (0)