Fixes error thrown when saving various forms: `Cannot set property

'name_api_error' of null`

Resolves #3822 & #3832
This commit is contained in:
Leigh Johnson 2016-11-01 22:27:26 -04:00
parent a0021f974a
commit 6d57d8f40b
9 changed files with 17 additions and 18 deletions

View File

@ -414,7 +414,7 @@ ProjectsAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log',
export function ProjectsEdit($scope, $rootScope, $compile, $location, $log,
$stateParams, ProjectsForm, Rest, Alert, ProcessErrors,
$stateParams, ProjectsForm, Rest, Alert, ProcessErrors, GenerateForm,
Prompt, ClearScope, GetBasePath, GetProjectPath, Authorization,
GetChoices, Empty, DebugForm, Wait, ProjectUpdate, $state, CreateSelect2, ToggleNotification, i18n) {
@ -587,7 +587,7 @@ export function ProjectsEdit($scope, $rootScope, $compile, $location, $log,
// Save changes to the parent
$scope.formSave = function() {
var fld, i, params;
//generator.clearApiErrors();
GenerateForm.clearApiErrors($scope);
Wait('start');
$rootScope.flashMessage = null;
params = {};

View File

@ -105,8 +105,7 @@ export function TeamsAdd($scope, $rootScope, $stateParams, TeamForm, GenerateFor
// Inject dynamic view
var defaultUrl = GetBasePath('teams'),
form = TeamForm,
generator = GenerateForm;
form = TeamForm;
init();
@ -120,7 +119,7 @@ export function TeamsAdd($scope, $rootScope, $stateParams, TeamForm, GenerateFor
// Save
$scope.formSave = function() {
var fld, data;
generator.clearApiErrors();
GenerateForm.clearApiErrors($scope);
Wait('start');
Rest.setUrl(defaultUrl);
data = {};
@ -216,7 +215,6 @@ export function TeamsEdit($scope, $rootScope, $stateParams,
$scope.formSave = function() {
$rootScope.flashMessage = null;
if ($scope[form.name + '_form'].$valid) {
Rest.setUrl(defaultUrl + id + '/');
var data = processNewData(form.fields);
Rest.put(data).success(function() {
$state.go($state.current, null, { reload: true });

View File

@ -202,7 +202,7 @@ function adhocController($q, $scope, $location, $stateParams,
"privilege_escalation": ""
};
GenerateForm.clearApiErrors();
GenerateForm.clearApiErrors($scope);
// populate data with the relevant form values
for (fld in adhocForm.fields) {

View File

@ -50,7 +50,7 @@ export default ['Rest', 'Wait',
}
$scope.formSave = function() {
generator.clearApiErrors();
generator.clearApiErrors($scope);
Wait('start');
Rest.setUrl(url + id + '/');
Rest.put({

View File

@ -280,7 +280,7 @@
function saveCompleted(id) {
$state.go('jobTemplates.edit', {id: id}, {reload: true});
$state.go('jobTemplates.edit', {job_template_id: id}, {reload: true});
}
if ($scope.removeTemplateSaveSuccess) {
@ -419,7 +419,7 @@
$scope.survey_enabled = false;
}
generator.clearApiErrors();
generator.clearApiErrors($scope);
Wait('start');
@ -501,6 +501,7 @@
} catch (err) {
Wait('stop');
console.log(err)
Alert("Error", "Error parsing extra variables. " +
"Parser returned: " + err);
}

View File

@ -542,7 +542,7 @@ export default
$scope.survey_enabled = false;
}
generator.clearApiErrors();
generator.clearApiErrors($scope);
Wait('start');

View File

@ -120,7 +120,7 @@ export default ['$rootScope', 'Rest', 'Wait', 'NotificationsFormObject',
var params,
v = $scope.notification_type.value;
generator.clearApiErrors();
generator.clearApiErrors($scope);
params = {
"name": $scope.name,
"description": $scope.description,

View File

@ -197,7 +197,7 @@ export default ['Rest', 'Wait',
var params,
v = $scope.notification_type.value;
generator.clearApiErrors();
generator.clearApiErrors($scope);
params = {
"name": $scope.name,
"description": $scope.description,

View File

@ -303,21 +303,21 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
return html;
},
clearApiErrors: function () {
clearApiErrors: function (scope) {
for (var fld in this.form.fields) {
if (this.form.fields[fld].sourceModel) {
this.scope[this.form.fields[fld].sourceModel + '_' + this.form.fields[fld].sourceField + '_api_error'] = '';
scope[this.form.fields[fld].sourceModel + '_' + this.form.fields[fld].sourceField + '_api_error'] = '';
$('[name="' + this.form.fields[fld].sourceModel + '_' + this.form.fields[fld].sourceField + '"]').removeClass('ng-invalid');
} else if (this.form.fields[fld].realName) {
this.scope[this.form.fields[fld].realName + '_api_error'] = '';
$('[name="' + this.form.fields[fld].realName + '"]').removeClass('ng-invalid');
} else {
this.scope[fld + '_api_error'] = '';
scope[fld + '_api_error'] = '';
$('[name="' + fld + '"]').removeClass('ng-invalid');
}
}
if (!this.scope.$$phase) {
this.scope.$digest();
if (!scope.$$phase) {
scope.$digest();
}
},