@@ -320,6 +320,18 @@ class AdminForth implements IAdminForth {
320320 { resource : AdminForthResource , record : any , adminUser : AdminUser , extra ?: HttpExtra }
321321 ) : Promise < { error ?: string , createdRecord ?: any } > {
322322
323+ // check if record with minValue or maxValue is within limits
324+ for ( const column of resource . columns . filter ( ( col ) => col . name in record
325+ && [ 'integer' , 'decimal' , 'float' ] . includes ( col . type )
326+ && ( col . minValue !== undefined || col . maxValue !== undefined ) ) ) {
327+ if ( column . minValue !== undefined && record [ column . name ] < column . minValue ) {
328+ return { error : `Value in "${ column . name } " must be greater than ${ column . minValue } ` } ;
329+ }
330+ if ( column . maxValue !== undefined && record [ column . name ] > column . maxValue ) {
331+ return { error : `Value in "${ column . name } " must be less than ${ column . maxValue } ` } ;
332+ }
333+ }
334+
323335 // execute hook if needed
324336 for ( const hook of listify ( resource . hooks ?. create ?. beforeSave ) ) {
325337 console . log ( '🪲 Hook beforeSave' , hook ) ;
@@ -385,6 +397,18 @@ class AdminForth implements IAdminForth {
385397 { resource : AdminForthResource , recordId : any , record : any , oldRecord : any , adminUser : AdminUser , extra ?: HttpExtra }
386398 ) : Promise < { error ?: string } > {
387399
400+ // check if record with minValue or maxValue is within limits
401+ for ( const column of resource . columns . filter ( ( col ) => col . name in record
402+ && [ 'integer' , 'decimal' , 'float' ] . includes ( col . type )
403+ && ( col . minValue !== undefined || col . maxValue !== undefined ) ) ) {
404+ if ( column . minValue !== undefined && record [ column . name ] < column . minValue ) {
405+ return { error : `Value in "${ column . name } " must be greater than ${ column . minValue } ` } ;
406+ }
407+ if ( column . maxValue !== undefined && record [ column . name ] > column . maxValue ) {
408+ return { error : `Value in "${ column . name } " must be less than ${ column . maxValue } ` } ;
409+ }
410+ }
411+
388412 // remove editReadonly columns from record
389413 for ( const column of resource . columns . filter ( ( col ) => col . editReadonly ) ) {
390414 if ( column . name in record )
0 commit comments