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

Jan, I'm having trouble understanding your question. Is your question in reference to the context of the original post, or something else?

thanks Justin, 

i have commented one line in client script and its working fine now

var eventName = "sp.form.record.updated";
if (response.isInsert) {
message = $scope.data.recordAddedMsg;
var search = $location.search();
search.sys_id = response.sys_id;
search.spa = 1;
//$location.search(search).replace(); commented this line 
} else
message = $scope.data.updatedMsg;

$scope.data.hideRelatedLists = hideRelatedLists();
$scope.$emit(eventName, $scope.data.f._fields);
$rootScope.$broadcast(eventName, $scope.data.f._fields);
$scope.status = message;
spUtil.addTrivialMessage(message);
$timeout(clearStatus, 2000);
}
}

Hi,

created custom widget with Script and added in Page .

HTML:

 <div class="panel panel-default">
<button type="button" class="btn btn-default" ng-if="data.showButton" ng-click="c.uiAction('update')">Update</button>
 </div>

Server :

(function() {
 
 // Get table & sys_id
 data.table = input.table || $sp.getParameter("table");
 data.sys_id = input.sys_id || $sp.getParameter("sys_id");
 
 // Valid GlideRecord
 gr = new GlideRecord(data.table);
 if (!gr.isValid())
 return;
 
 // Valid sys_id
 if (!gr.get(data.sys_id))
 return;
    
//Button Visibility    
 if (data.table == 'u_my_shuttle_requesting' && gr.u_state=='Update Needed' && gr.u_requestor_name == gs.getUserID()) {
     data.showButton=true;
 }else{
     data.showButton=false;
 }
   
 if (input && input.action) {
 var action = input.action;
 
 // If Incident table
 if (data.table == 'u_my_shuttle_requesting') {
 if (action == 'update') {
 // Do something else
   gr.setValue('u_state', 'Request Updated');
   gr.update();
   data.fltr='/ghrc';
 }
 }
 }
})();

 

Client:

function($scope,$location) {
 var c = this;
 c.uiAction = function(action) {
     if(action == 'update'){
var r = confirm("Are you sure you want to update this request?");
if(r == false){
return;
}
}
 c.data.action = action;
 c.server.update().then(function() {
 c.data.action = undefined;
$location.url($scope.data.fltr);
 })
 }

$scope.uiAction = function() {
       for (var x in $scope.data.f._fields) {
               g_form.setMandatory(x, false);
       }
       $scope.triggerUIAction($scope.getPrimaryAction());
}

}

i have updated fields on form . i want to Save whole form with out discard any values , comments box values ..by using bold script- form is not Saving.

Can Please help me here to Fix this one ? ???

 

brendanwilson84
Kilo Guru

Hi Justin,



Me again! One last question



i am trying to place a cancel button on the form, when clicked it would show a pop up to say nothing will be saved and redirect out of form, if cancel pressed, stay in form.



Ive added html


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


              Cancel



then on the client ive put



function ($scope, spUtil, $location) {


  $scope.$on('data_table.click', function(e, parms){


  var p = $scope.data.page_id || 'form';


  var s = {id: p, table: parms.table, sys_id: parms.sys_id, view: 'sp'};


  $location.search(s);


  });




  $scope.brendanCan = function(){


  if(confirm("Your changes will not be saved") == false){


return false;


}else{


$location.url('/online_referral?id=onlinerefhome');


}


}}



This works if i built a widget for it, but doenst seem to work on the form widget


brendanwilson84
Kilo Guru

Hi Justin



Got it working!



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


              Cancel




$scope.brendanCan = function() {


if(confirm("Your changes will not be saved")){


$location.url('/online_referral?id=onlinerefhome');


}else{


return false;


}