Require an attachment

Is there a way to require that a person attach an item to the form?
Thanks
Jennifer

Hello @jktodd007,

You can add a custom validator to the form. So when a user submits the form and no files attached, he will receive an error message.

Please see the code sample below.


fd.spRendered(function(){

fd.field('Attachments').validators.push({
        name: 'Attachments Validation',
        error: "Please add attachment",
        validate: function() {
            if (fd.field('Attachments').value.length == 0) {
                    return false;
                }
            return true;
    }
})

});

I tried the code as you have it here as well as putting in a Before save and it did not work

Here is my code
fd.spBeforeSave() {
fd.field('Attachments').validators.push({
name: 'Attachments Validation',
error: "Please add attachment",
validate: function() {
if (fd.field('Attachments').value.length == 0) {
return true;
}
return false;
}
})

var str = fd.field('EmployeeID').value;
var res = str.toUpperCase();
fd.field('EmployeeID').value = res;
});

@jktodd007,

It should be used under fd.spRendered event handler. It is my mistake in the code, I'm sorry.
Please see below. the correct one


fd.spRendered(function(){

fd.field('Attachments').validators.push({
        name: 'Attachments Validation',
        error: "Please add attachment",
        validate: function() {
            if (fd.field('Attachments').value.length == 0) {
                    return false;
                }
            return true;
    }
})

});