Problems with onCustomValidation

The picture shall be uploaded to a gallery and I use an uploadbutton with the name “upload” and another button for submitting which I don´t think has to be mentioned in the code (or am i wrong?). When I tried with uploading an image that exceeds 2 mb the image was still uploaded and the number of files can also exceed my restriction of 6 images so the code is obviously not working.

Should I skip this rows or how can I solve the problem?

let sliderpics = $w ( “#dataset3” ). getCurrentItem (). sliderpics ;
let files = $w ( ‘#upload’ ). value ;
files . forEach (( file ) => {

 $w ( "#dataset3" ). setFieldValue ( sliderpics ); 
 $w ( "#dataset3" ). save (); 

This is my current code

$w . onReady ( function () {

$w ( “#dataset3” ). onReady ( () => {
$w ( “#upload” ). onCustomValidation ( ( value , reject ) => {
let sliderpics = $w ( “#dataset3” ). getCurrentItem (). sliderpics ;
let files = $w ( ‘#upload’ ). value ;
files . forEach (( file ) => {
if ( File [ 0 ]. fileSize === 2000000 ) { reject ( “File size exceeds 2 Mb” );}
if ( File [ 0 ]. fileLimit === 6 ) { reject ( “FileLimit exceeds 6 images” );}
$w ( “#text423” ). show ();
console . log ( “Not valid image” );
$w ( “#dataset3” ). setFieldValue ( sliderpics );
$w ( “#dataset3” ). save ();
$w ( “#text424” ). show ();
console . log ( “Image uploaded” );
})
})
});

An alternate version that doesn´t work either

$w . onReady ( function () {

$w ( “#dataset3” ). onReady ( () => {
$w ( “#upload” ). onCustomValidation ( ( value , reject , valid ) => {
let sliderpics = $w ( “#dataset3” ). getCurrentItem (). sliderpics ;
let files = $w ( ‘#upload’ ). value ;
files . forEach (( file ) => {
if ( File [ 0 ]. fileSize === 2100000 ) { reject ( “File size exceeds 2 Mb” );}
if ( File [ 0 ]. fileLimit === 7 ) { reject ( “FileLimit exceeds 6 images” );}
$w ( “#text423” ). show ();
console . log ( “Not valid image” );
if ( File [ 0 ]. fileSize === 1990000 ) { valid ( “File size is less than 2 Mb” );}
if ( File [ 0 ]. fileLimit === 6 ) { valid ( “The images is less than 7” );}
$w ( “#dataset3” ). setFieldValue ( sliderpics );
$w ( “#dataset3” ). save ();
$w ( “#text424” ). show ();
console . log ( “Image is uploaded” );
})
})
});

A third version without results

$w ( “#dataset3” ). onReady ( () => {
$w ( “#upload” ). onCustomValidation ( ( value , reject , valid ) => {
let sliderpics = $w ( “#dataset3” ). getCurrentItem (). sliderpics ;
let files = $w ( ‘#upload’ ). value ;
files . forEach (( file ) => {
if ( file [ 0 ]. size > 2010000 ) { reject ( “File size exceeds 2 Mb” );
if ( file [ 0 ]. limit > 7 ) { reject ( “File limit exceeds 6 images” );
$w ( “#text423” ). show ();
} else {
( file [ 0 ]. size > valid ); { valid ( “File size is less than 2 Mb” );
( file [ 0 ]. limit > valid ); { valid ( “The images is less than 7” );
$w ( “#dataset3” ). setFieldValue ( sliderpics );
$w ( “#dataset3” ). save ();
$w ( “#text424” ). show ();
console . log ( file );
})
})
});

This is the absolute hardest problem I have experienced when it comes to coding on top of many other difficulties so I really need help but I get no answers here :neutral_face: