fixed submitting delay

This commit is contained in:
David Baldwynn 2016-04-28 20:13:37 -07:00
parent f004b389cb
commit f2211438ce

View file

@ -138,30 +138,29 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
}
};
$scope.submitForm = function(){
$scope.submitForm = function() {
var _timeElapsed = TimeCounter.stopClock();
$scope.loading = true;
var form = _.cloneDeep($scope.myform);
form.timeElapsed = _timeElapsed;
form.percentageComplete = $filter('formValidity')($scope.myform)/$scope.myform.visible_form_fields.length*100;
form.percentageComplete = $filter('formValidity')($scope.myform) / $scope.myform.visible_form_fields.length * 100;
delete form.visible_form_fields;
$scope.submitPromise = $http.post('/forms/'+$scope.myform._id, form)
.success(function(data, status, headers){
setTimeout(function () {
$scope.submitPromise = $http.post('/forms/' + $scope.myform._id, form)
.success(function (data, status, headers) {
console.log('form submitted successfully');
setTimeout(function() {
$scope.myform.submitted = true;
$scope.loading = false;
}, 20);
})
.error(function(error){
setTimeout(function(){
.error(function (error) {
$scope.loading = false;
console.log(error);
$scope.error = error.message;
}, 20);
});
}, 500);
};
//Load our form when the page is ready