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

brendanwilson84
Kilo Guru

Hi juabbott



Me again, made some good progress on buttons, now i have a requirement to show/hide them for example if status is draft



Have been trying the following, the button functionality is working, however, hiding the button if cancelled or submitted is not/ many thanks



Here is the code,



HTML


<button type="button" ng-click="saveAndExit()" ng-if="showSaveAndExit" data-ng-init="myFunction()" class="btn btn-primary action-btn pull-right">Save and Exit</button>






CLIENT




$scope.showSaveAndExit = true;


$scope.myFunction = function() {


alert("page load");


if(g_form.getValue('u_status') === 'Cancelled' || g_form.getValue('u_status') === 'Submitted'){


$scope.showSaveAndExit = false; //hide button if status is cancelled or submitted


alert("if");


}


else{


$scope.showSaveAndExit = false;


alert("else");


}


}


I got this to work by doing the following. You'd obviously need to update it to use your own field names and values.



Add to the very bottom of the Client Script:



$scope.$on('field.change', function() {


      var state = $scope.c.data.f._fields.state.value;


      if (state == 😎 {


              $scope.hideButton = true;


      } else {


              $scope.hideButton = false;


      }


});



Modify the button tag to include an ng-hide:



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


      Save as Draft


</button>



Hope that helps!


brendanwilson84
Kilo Guru

Once again you have saved me!



I owe you a drink and lots of them, thank a million