Requiring attachment based on other field
Hello,
i am trying to require attachment on save button if name or address fields are filled out. could you please advice how to accomplish this? with my code it checks for attachment regardless of what values are filled out it sends out alert to attach an attachment. Please advise. Thanks in advance!
if ((fd.field('Name').value() != " ") && ($('#idAttachmentsTable tr').length == 0)){
if ((fd.field('Mailing').value() != " ") && ($('#idAttachmentsTable tr').length == 0))
{
alert('Please attach an attachment as supporting document');
return false;
}
return true;
};
i am trying to require attachment on save button if name or address fields are filled out. could you please advice how to accomplish this? with my code it checks for attachment regardless of what values are filled out it sends out alert to attach an attachment. Please advise. Thanks in advance!
if ((fd.field('Name').value() != " ") && ($('#idAttachmentsTable tr').length == 0)){
if ((fd.field('Mailing').value() != " ") && ($('#idAttachmentsTable tr').length == 0))
{
alert('Please attach an attachment as supporting document');
return false;
}
return true;
};
Hi!
Try this:
However, I don't know what Name and Mailing fields' types are, take a look here at the various field types and corresponding ways of getting their values: http://spform.com/forms-designer- ... eld-values
Try this:
Code: Select all
fd.onsubmit(function(){
if ((fd.field('Name').value() || fd.field('Mailing').value()) && fd.field('Attachments').control()._el().find('#idAttachmentsTable tr').length == 0) {
alert('Attachments is a required field!');
return false;
}
return true;
})
However, I don't know what Name and Mailing fields' types are, take a look here at the various field types and corresponding ways of getting their values: http://spform.com/forms-designer- ... eld-values
Probably because you have things like this there
Whereas you probably mean
Code: Select all
fd.field('Mailing').value() != " "
Code: Select all
fd.field('Mailing').value() != ""
"As well validations always returns false when i use your method for 3 fields. for example name,address and phone. If any of the field has value attachment can't be blank."
Show us the code and tell us how you expect it to work.
Regarding the code you posted initially what you are saying with it is:
if name is not one empty space and there are no Attachments
and mailing is not one empty space and there are no Attachments
in that case alert and return false
otherwise return true
I presume that's not what you want. If you want to display different alert messages based on different fields being empty or not, you should do:
Show us the code and tell us how you expect it to work.
Regarding the code you posted initially what you are saying with it is:
if name is not one empty space and there are no Attachments
and mailing is not one empty space and there are no Attachments
in that case alert and return false
otherwise return true
I presume that's not what you want. If you want to display different alert messages based on different fields being empty or not, you should do:
Code: Select all
fd.onsubmit(function(){
if (fd.field('Name').value() && fd.field('Attachments').control()._el().find('#idAttachmentsTable tr').length == 0) {
alert('alert 1');
return false;
}
if (fd.field('Mailing').value() && fd.field('Attachments').control()._el().find('#idAttachmentsTable tr').length == 0){
alert('alert 2');
return false;
}
return true;
})
-
- Information
-
Who is online
Users browsing this forum: No registered users and 15 guests