onsubmit require attachement form widget

brendanwilson84
Kilo Guru

Hi Guys

I am wondering if any of you guys have done this.

I am using the form widget and have buttons as below.

Submit Online Referral is a server side button from the backend

Cancel and save as draft is custom buttons

Cancels just leaves the form, and save as draft saves the form without needed to complete required fields.

I have a requirement to make attachment mandatory if users states yes to has attachments and only when they click on the submit referral.

In the back-end, i would have used business rules previous to do this, but not sure how i could do this on the portal.

find_real_file.png

7 REPLIES 7

Hi,



Please paste it in here as this is your submit action button




$scope.triggerUIAction = function(action) {


if ($scope.data.disableUIActions)


return;



if (g_form) {


$timeout(function() {




//paste it here





g_form.submit(action.action_name || action.sys_id);




}


)}


}


brendanwilson84
Kilo Guru

Thank you



Ive added the following but no joy



$scope.action.name = function(){


var attLength=$scope.get-attachment.length;


if(attLength==0){


g_form.addErrorMessage('Your are required to attach');


return false;


}}


Hi Brendon,



I guess you are adding it in wrong place,


You need to add it to the function when you are going to save the request.


Also, its $scope.attachment.length and not $scope.get-attachment.length as per OOB.



Please try the below code and see the outcome.


You can also try to debug then if it is affecting something else.




$scope.triggerUIAction = function(action) {


var attLength= $scope.attachments.length;


if(attLength==0){


g_form.addErrorMessage("Please attach atleast one item");


return false;


}




if ($scope.data.disableUIActions)


return;




if (g_form) {


$timeout(function() {


g_form.submit(action.action_name || action.sys_id);






}


)}


}