Skip to main content
williamm0010
July 25, 2022
Solved

File Upload Validate Extension On Button Disabled

  • July 25, 2022
  • 7 replies
  • 0 views

I am trying to keep the submit button disabled if they have not selected a file and if the file is not a CSV extension.

The button disable works fine for check for no file but the file extension checking is not working and can not figure out why.

In the below code the first if is working fine but the second one it gets this error   

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function 'document' [line 45]: The passed parameter(s) are of the wrong type. Received the type Text.   and can not figure out why.  Is there a better way to check this?  Thank you for any help on this, also the ri!csvFile_txt it saves into show this     [Document: 383603]   as the value for it.  The upload also works fine with the csv file as well, just having the issue on the disabled validation part.

primaryButtons: {
      a!buttonWidget(
        label: "Submit",
        submit: true,
        style: "PRIMARY",
        disabled: if(
          rule!APN_isEmpty(ri!csvFile_txt),
          true(),
          if(
            find("CSV", a!fileUploadField(value: upper(document(ri!csvFile_txt, "extension")))) > 0,
            false(),
            true()
          )
        )
      )
    }

Best answer by stefanhelzle0001

The best way to add a validation to your form is to use the validation feature of each input component. Is there a specific reason for not using that? 

7 replies

stefanhelzle0001
Brainy
July 25, 2022

The best way to add a validation to your form is to use the validation feature of each input component. Is there a specific reason for not using that? 

williamm0010
July 25, 2022

I am using the validation feature on the upload file component, when you pick a file that is not a csv file it tells the user the file is invalid and to remove it and pick a csv file.  But I need the submit button to stay disabled until they pick a csv file.

stefanhelzle0001
Brainy
July 25, 2022

Why do you "need" to do that? Is that a requirement? If yes, why?

mikes0011
Brainy
July 25, 2022

The code you're trying to execute here is invalid in a few different ways.

find("CSV", a!fileUploadField(value: upper(document(ri!csvFile_txt, "extension"))))

And even if you did correct that to do what I assume you're trying to do, it's still unsupported functionality.

The passed parameter(s) are of the wrong type. Received the type Text.   

This is because you're trying to pass in a "value" for the File Upload Field, but the "value" you're passing is text.  The value for the File Upload Field must be document, not text.

The Expression Guru