@@ -90,34 +90,39 @@ const _validateFormat = (rows, hasHeader, cols, options) => {
9090 const errors = [ ] ;
9191 const knownColsCount = colsData . length ;
9292 const startIndex = hasHeader ? 1 : 0 ;
93+
94+ const colMeta = cols . map ( ( col ) => ( {
95+ field : col . field ,
96+ type : _getColTypeFromTypeArray ( col . type ) ,
97+ acceptsEmptyFields : col . acceptsEmptyFields ?? col . cellEditorParams ?. acceptsEmptyFields ?? false ,
98+ colOptions : {
99+ ...options ,
100+ enumValues : col . enumValues ?? col . cellEditorParams ?. enumValues ,
101+ minValue : col . minValue ,
102+ maxValue : col . maxValue ,
103+ } ,
104+ } ) ) ;
105+
93106 for ( let rowIndex = startIndex ; rowIndex < rows . length ; rowIndex ++ ) {
94107 const row = rows [ rowIndex ] ;
95108 while ( row [ row . length - 1 ] === undefined && row . length > knownColsCount ) row . pop ( ) ;
96- if ( row . length !== knownColsCount || row . includes ( undefined ) )
97- _forgeColumnsCountError ( row , rowIndex + 1 , colsData , errors ) ;
98- row . forEach ( ( rowCell , colIndex ) => {
99- if ( colIndex < knownColsCount ) {
100- const colType = colsData [ colIndex ] . type ;
101- if ( colType && rowCell !== undefined ) {
102- // use of cellEditorParams is deprecated
103- const colOptions = {
104- ...options ,
105- enumValues : colsData [ colIndex ] ?. enumValues ?? colsData [ colIndex ] ?. cellEditorParams ?. enumValues ,
106- minValue : colsData [ colIndex ] ?. minValue ,
107- maxValue : colsData [ colIndex ] ?. maxValue ,
108- } ;
109- const acceptsEmptyFields =
110- // use of cellEditorParams is deprecated
111- colsData [ colIndex ] . acceptsEmptyFields ?? colsData [ colIndex ] . cellEditorParams ?. acceptsEmptyFields ?? false ;
112- const validationResult = ValidationUtils . isValid ( rowCell , colType , colOptions , acceptsEmptyFields ) ;
113- if ( validationResult !== true ) {
114- const { summary : errorSummary , context : errorContext } = validationResult ;
115- const errorLoc = `Line ${ rowIndex + 1 } , Column ${ colIndex + 1 } ("${ colsData [ colIndex ] . field } ")` ;
116- errors . push ( new PanelError ( errorSummary , errorLoc , errorContext ) ) ;
117- }
118- }
109+ if ( row . length !== knownColsCount || row . includes ( undefined ) ) {
110+ _forgeColumnsCountError ( row , rowIndex + 1 , cols , errors ) ;
111+ continue ;
112+ }
113+
114+ for ( let colIndex = 0 ; colIndex < knownColsCount ; colIndex ++ ) {
115+ const { type, colOptions, acceptsEmptyFields, field } = colMeta [ colIndex ] ;
116+ const value = row [ colIndex ] ;
117+ if ( value === undefined ) continue ;
118+
119+ const validationResult = ValidationUtils . isValid ( value , type , colOptions , acceptsEmptyFields ) ;
120+ if ( validationResult !== true ) {
121+ const { summary : errorSummary , context : errorContext } = validationResult ;
122+ const errorLoc = `Line ${ rowIndex + 1 } , Column ${ colIndex + 1 } ("${ field } ")` ;
123+ errors . push ( new PanelError ( errorSummary , errorLoc , errorContext ) ) ;
119124 }
120- } ) ;
125+ }
121126 }
122127
123128 return errors ;
0 commit comments