File Upload Validation

How to put a Validation on a file upload field so that the user could only upload images.

OriginalPostID-249057

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer
    @tanvirs , you can do something as below
    =======================================================
    a!formLayout(
    firstColumnContents: {
    a!fileUploadField(
    label: "Upload a File",
    labelPosition: "ABOVE",
    saveInto: ri!document,
    validations: {}
    )

    },
    secondColumncontents:{

    },
    buttons: a!buttonLayout(
    primaryButtons: a!buttonWidgetSubmit(
    label:"Submit",
    style: "PRIMARY"
    )
    ),
    validations:{
    if(
    or(
    find("jpg", a!fileUploadField(value: ri!document)),
    find("jpeg", a!fileUploadField(value: ri!document)),
    find("png", a!fileUploadField(value: ri!document)),
    find("ico", a!fileUploadField(value: ri!document)),
    find("gif", a!fileUploadField(value: ri!document)),
    find("bmp", a!fileUploadField(value: ri!document))
    )>0,"Invalid Format",{}

    )



    /* if(
    find("jpg", a!fileUploadField(value: ri!document))=0,{},
    "Invalid Format"
    )*/

    }
    )
    ==========================
    Hope this will help you
Reply
  • +1
    Certified Lead Developer
    @tanvirs , you can do something as below
    =======================================================
    a!formLayout(
    firstColumnContents: {
    a!fileUploadField(
    label: "Upload a File",
    labelPosition: "ABOVE",
    saveInto: ri!document,
    validations: {}
    )

    },
    secondColumncontents:{

    },
    buttons: a!buttonLayout(
    primaryButtons: a!buttonWidgetSubmit(
    label:"Submit",
    style: "PRIMARY"
    )
    ),
    validations:{
    if(
    or(
    find("jpg", a!fileUploadField(value: ri!document)),
    find("jpeg", a!fileUploadField(value: ri!document)),
    find("png", a!fileUploadField(value: ri!document)),
    find("ico", a!fileUploadField(value: ri!document)),
    find("gif", a!fileUploadField(value: ri!document)),
    find("bmp", a!fileUploadField(value: ri!document))
    )>0,"Invalid Format",{}

    )



    /* if(
    find("jpg", a!fileUploadField(value: ri!document))=0,{},
    "Invalid Format"
    )*/

    }
    )
    ==========================
    Hope this will help you
Children
No Data