Using validators
Using validators

Hi
I'm trying to use a validator inside an upload field. I need to check if some variable is eq to -1 but am not sure how to do it. Here's what I need using standard c#:
editor.Field(new Field("UserFileID")
.SetFormatter(Format.IfEmpty(0))
.Validator(if (intCdrFrmtTpe == -1) return "Ensure a format type is selected."
))
.Upload(new Upload(strFolder + @"\__NAME____EXTN__")
.Db("UserFiles", "ID", new Dictionary<string, object>
{
{"WebPath", Upload.DbType.WebPath},
{"SystemPath", Upload.DbType.SystemPath},
{"FileName", Upload.DbType.FileName},
{"FileSize", Upload.DbType.FileSize}
})
)
);
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The goal is to evaluate intCdrFrmtTpe and return the message "Ensure a format type is selected."
Hi
I decided to run the check via the preUpload event instead. Works fine. Thanks
That's currently the only way, since the upload is async to the rest of the form. Keep in mind that it is still possible for the user to change the
intCdrFrmtTpe
field's value after they've uploaded the file, but before submitting the form as a whole.Allan