Required upload file

Required upload file

dynasoftdynasoft Posts: 422Questions: 67Answers: 3

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: Hi, how can I make uploadinga file a requirement. The following does not trigger the Required validator:

                editor.Field(new Field("FTR.UserFileID")
                    .Validator(Validation.Required(new ValidationOpts
                    {
                        Message = lblo.lblEnsureFileUploaded
                    }))
                    .Upload(new Upload(SetGetUserPriceListsDir + @"\__ID____EXTN__")
                        .Db("UserFiles", "id", new Dictionary<string, object>
                        {
                            {"WebPath", Upload.DbType.WebPath},
                            {"SystemPath", Upload.DbType.SystemPath},
                            {"FileName", Upload.DbType.FileName},
                            {"FileSize", Upload.DbType.FileSize}
                        })
                    )
                );

Also what is the syntax for including functions in the validtors for .net. The following on https://editor.datatables.net/manual/php/upload#Validation is for php:

Upload::inst( ... )
->validator( function ( $file ) {
if ( $file['size'] >= 500000 ) {
return "Files must be smaller than 500K";
}
return null;
} )

Many thanks.

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    The .NET manual page for validation shows the .NET upload syntax. The download package for .NET also includes an upload example matching the PHP one.

    Regarding the required validator, that looks like the correct way of doing it. It should give you an error when you attempt to submit the form. What happens when you do?

    Allan

  • dynasoftdynasoft Posts: 422Questions: 67Answers: 3

    Many thanks. Not sure what happened but the required validator wasn't triggering before but got it to work today. Thanks again.

This discussion has been closed.