FileUpload Validation

Certified Senior Developer

I am implementing a gridRowLayout. Inside the gridRowLayout I am implementing a fileUpload field. 

So that I can add a new row dynamically and for each row I can upload 1 document.

But the demand here is ... I cant upload same files again and again (i.e. I cant upload same files in different rows) . But I am not quite sure how to do the validation for it. Can anyone help me with this ? 

This validation I have added for fileName. But as you see I could upload same files. I need validation to say that File Already Uploaded. Is there a way to do this validation ?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hi,

    Can you share your code snippet?

  • 0
    Certified Senior Developer
    in reply to Shikha

    a!localVariables(
    local!uploadedDocuments: index(ri!data, "uploadedFiles", null),
    a!gridLayout(
    label: "UPLOAD FILES",
    headerCells: {
    ..
    },
    columnConfigs: {
    ..
    },
    rows: {
    a!forEach(
    items: local!uploadedDocuments,
    expression: {
    a!gridRowLayout(
    contents: {
    a!fileUploadField(
    target: cons!TargetFolder,
    label: "Attach Documents",
    labelPosition: "ABOVE",
    maxSelections: 1,
    value: ..,
    saveInto: {..},
    ),
    a!richTextDisplayField(
    value: a!richTextIcon(
    icon: "times",
    link: a!dynamicLink(
    saveInto: {..}
    ),
    linkStyle: "STANDALONE",
    color: "NEGATIVE"
    ),
    showWhen: not(ri!readOnly)
    )
    }
    )
    }
    )
    },
    addRowLink: a!dynamicLink(
    label: "Attach New Document ",
    saveInto: {..},
    showWhen: not(ri!readOnly)
    )
    ),
    )

  • +1
    Certified Senior Developer
    in reply to GautamShenoy

    There is no validation defined here , but sharing a sample code which you can try.

    {
      a!fileUploadField(
        label: "File Upload",
        labelPosition: "ABOVE",
        target: cons!DOCUMENTFOLDERCONSTANT,
        value: ri!documents,
        saveInto: ri!documents,
        validations: reject(
          fn!isnull,
          a!forEach(
            items: union({ fv!files.name }, { fv!files.name }),
            expression: if(
              count(wherecontains(fv!item, { fv!files.name })) > 1,
              fv!item & " is uploaded by you earlier please remove it",
              null
            )
          )
        ),
        buttonDisplay: "LABEL"
      )
    }/* documents RI is of type document and array type*/

Reply
  • +1
    Certified Senior Developer
    in reply to GautamShenoy

    There is no validation defined here , but sharing a sample code which you can try.

    {
      a!fileUploadField(
        label: "File Upload",
        labelPosition: "ABOVE",
        target: cons!DOCUMENTFOLDERCONSTANT,
        value: ri!documents,
        saveInto: ri!documents,
        validations: reject(
          fn!isnull,
          a!forEach(
            items: union({ fv!files.name }, { fv!files.name }),
            expression: if(
              count(wherecontains(fv!item, { fv!files.name })) > 1,
              fv!item & " is uploaded by you earlier please remove it",
              null
            )
          )
        ),
        buttonDisplay: "LABEL"
      )
    }/* documents RI is of type document and array type*/

Children