buttons on form widget

brendanwilson84
Kilo Guru

Hi Guys

I have a form widget, in that we are going to be creating records from. I can get my form on page fine, using sys_id=-1.

It is quite a lengthy form so therefore they required a save as draft and submit button. Using a record producer is prob out of the question now as they want to save as draft and come back later to complete.

I cloned the form widget and looked at the html part and could get the submit button added

find_real_file.png

However, what i need is, if save is clicked, then remove the required field stamp and save the record as a draft. I have a draft state in my form.   My coding experience is pretty low, especially on the portal side

Any Pointers or anyone do this before?

1 ACCEPTED SOLUTION

Justin Abbott
Giga Guru

You could try this, Brendan.



HTML Button near the bottom of the form:


<button type="button" ng-click="saveAsDraft()" class="btn btn-primary action-btn pull-right">


              Save as Draft


</button>



Method added to the Client Script (controller), just before the last brace.


$scope.saveAsDraft = function() {


      for (var x in $scope.data.f._fields) {


              g_form.setMandatory(x, false);


      }


      $scope.triggerUIAction($scope.getPrimaryAction());


}



The saveAsDraft function gets all of the fields on the form, sets them as not mandatory, then triggers the save.


View solution in original post

17 REPLIES 17

Justin, you know your portal!



I wish i could mark that correct to.   Thanks a million


Some reason it's not working for me, I can see ng-click is getting fired but it's not setting mandatory for false nor it's saving the record. 

I added the code to the end.

I can see below error on the console though.

TypeError: Cannot read property 'action_name' of null

any thoughts?

function appendError(error) {
		$scope.errorMessages.push(error);
		spUtil.addErrorMessage(error.msg + error.fileName);
	}
	
	$scope.saveAsDraft = function() {
       for(var x in $scope.data.f._fields) {
               g_form.setMandatory(x, false);
       }
       $scope.triggerUIAction($scope.getPrimaryAction());
}

Some reason it's not working for me, I can see ng-click is getting fired but it's not setting mandatory for false nor it's saving the record. 

I added the code to the end.

I can see below error on the console though.

TypeError: Cannot read property 'action_name' of null

any thoughts?

 

function appendError(error) {
		$scope.errorMessages.push(error);
		spUtil.addErrorMessage(error.msg + error.fileName);
	}
	
	$scope.saveAsDraft = function() {
       for(var x in $scope.data.f._fields) {
               g_form.setMandatory(x, false);
       }
       $scope.triggerUIAction($scope.getPrimaryAction());
}

did you get Solution for this ?

HI Justin,

i have cloned the form widget and given the link to redirect after save. Its working for the exisitng records. But for the new records its going to some other page with record not found error. COuld you please guide here .thanks in advance

find_real_file.png