Validation for Array of Documents

Certified Senior Developer

Hi All,

I have multiple sections where the user can upload document and for each section we have "add document" button like below,

I have to validate for document size if it is more than 10MB,and this validation is for add document button.I am not getting how to validate the document based on index using fv!files.

Because of this,if user adds more than 10MB in 1st sec and adds less than 10 MB in 2nd sec,for both section it validates for "Add Document" button.

Please help me how to resolve this.

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    I don't use ValidationGroups often.  But this seems like a time it might work.

    Your problem is you're adding everything to the same ValidationGroup tag.  As far as I know, the ValidationGroup tag doesn't care about on-form positional context or anything like that.

    Remember that ValidationGroup is just a string - if your file upload fields and "add document" buttons are part of an array, then you could just append the current index to the validation group text, meaning each subsection with its own upload / button pair would have its own validation group.

    I'd strongly caution you though - you're submitting this form on the first press of a valid "add document" button.  As soon as that's pressed, *all* file upload field contents will be persisted to their target Appian folder, regardless of whether they pass the validation check in their own section.  If you're submitting the form and re-loading it again to allow the user to work on the next document, then all documents added to any file upload field up to that point will now be sitting in their target folders, even if the user then proceeds to remove one or more document(s) and upload replacements.  Thus I'd concentrate most on a solution where the user uploads all needed files and all are validated *before submission*.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Hi Mike, thanks for the reply. I am submitting this form every time on click of add document because I want to show the user added doc as a link to download the document ,please let me know if there is anyway to achieve this without submitting the form?

  • 0
    Certified Lead Developer
    in reply to Jansi J

    If the user is adding one document at a time (and you don't allow them to remove documents that've already been added and submitted) then that's fine.  It's just something you need to keep careful control of during design to keep your filesystem from getting cluttered with abandoned files that a user uploaded on one step then replaced on a subsequent step.

    To confirm, uploading files does require the form to be sumitted, at least at some point.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    After your statement I guess the result of my current design is expected scenario, in my current design if there is 5 section of upload documents and user uploaded 3 section docs out of 5,where 1st sec doc is more than 10 MB and next 2 sec docs are less than 10MB,then all the "add doc" button not submits the form due to the 1st uploaded doc(>10MB),which will prevent from saving the max size docs into the appian folder.

    Please let me know if I am wrong about this or in any other case it will fail?

  • 0
    Certified Lead Developer
    in reply to Jansi J

    that all sounds OK so far - my real question here is, what does it add exactly to have an "add document" button on each repeated section, where there are many all showing at the same time and you have no idea which one the user might click on (and why) at any particular time?

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    In our use case we have different multiple sections(cdt array),so only when the user click on "add document" for particular section, then that respective doc will be added in the respective array index, and when they remove the added document, it will be removed from respective array index.

  • 0
    Certified Lead Developer
    in reply to Jansi J

    I don't understand why that requires an "add document" button.  You should simply be able to do that using the saveInto of the file upload field.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    On click of "Add document" it saves the particular document into appian folder and we can show the added document as a link to download the respective document.

  • 0
    Certified Lead Developer
    in reply to Jansi J

    The section-level "add document" button still doesn't seem to add anything that a form-level button wouldn't do.

    And having it be form-level would probably be better since you presumably don't want a user uploading a 20MB document to section 1 (and not clicking the button), then going to section 2, uploading a 1MB document, clicking "add document", and both documents are submitted to the filesystem...

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Thanks Mike for your detailed explanation. I tested the scenario which you told,added 20 MB document in section 1(not clicked on "Add doc" button),then added 1MB document in section 2(clicked on "Add doc"button),no doc is saved in folder(form not submitted) because it throws validation for 1st section document.

    I am able to add documents to other section only if I correct the 20MB files.

Reply
  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Thanks Mike for your detailed explanation. I tested the scenario which you told,added 20 MB document in section 1(not clicked on "Add doc" button),then added 1MB document in section 2(clicked on "Add doc"button),no doc is saved in folder(form not submitted) because it throws validation for 1st section document.

    I am able to add documents to other section only if I correct the 20MB files.

Children
No Data