Using validators

Using validators

dynasoftdynasoft Posts: 422Questions: 67Answers: 3

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

Answers

  • dynasoftdynasoft Posts: 422Questions: 67Answers: 3

    The goal is to evaluate intCdrFrmtTpe and return the message "Ensure a format type is selected."

  • dynasoftdynasoft Posts: 422Questions: 67Answers: 3
    Answer ✓

    Hi

    I decided to run the check via the preUpload event instead. Works fine. Thanks

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    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

This discussion has been closed.