The CreatorCon Call for Content is officially open! Get started here.

Attachment Mandatory with message if attachment isnt provided

HenryD
Tera Guru

Hello, currently i am trying to do a client script that makes my catalog item have to submit a attachment and its mandatory, also want to add a message if they dont add a mandatory for it to submit. i tried using the variable attachment but i need to do it with the user adding the attachment to the paper clip on top of the catalog item. i have been researching tips and tricks but none seem to work for me, if anyone has done this lately or can point me to the righ direction i appreciate it. thank you in advance 

1 ACCEPTED SOLUTION

Hi,

My apologies for all the back and forth. I was hoping that the above code would work, but apparently not.

I've now tested this myself, because I didn't want to suggest you something else and have it be incorrect (previously, I thought the other code pieces did work).

So this works for me:

function onSubmit() {
    var attachments = document.getElementById('header_attachment_list_label');
    if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
        alert("Please add at least 1 attachment in order to submit request");
        return false;
    }
}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

11 REPLIES 11

Allen Andreas
Administrator
Administrator

Hi,

Within the catalog item settings, have you tried simply checking the attachment field?

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

thanks for the reply, yes i have tried the mandatory attachment but for some reason when i submit the catalog item it is still be processed and submitted. not sure why 

to follow up on your suggestion, this does indeed work on the portal side, but on the backend view it still lets me process this 

Hi,

For the desktop UI, you can create an onSubmit client script and then use this script:

function onSubmit() {
  
	if (this.document.getElementsByClassName('get-attachment').length == 0) {
		g_form.addErrorMessage(getMessage('attachment_mandatory'));

		return false;
	}	
   
}

You may need to add the "Isolate script" field to your client script form and then uncheck the box for this one.

Set the UI to only desktop (since the mandatory attachment checkbox on Portal Settings will take care of the portal).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!