From ea4b435ea7513745f41595ff59af18f7adc7abf3 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Wed, 1 Jul 2020 11:59:05 -0400 Subject: [PATCH 1/2] Ignore required field validation for booleans --- .../client/lib/components/input/base.controller.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/lib/components/input/base.controller.js b/awx/ui/client/lib/components/input/base.controller.js index eabd536e34..9a08ed0f2e 100644 --- a/awx/ui/client/lib/components/input/base.controller.js +++ b/awx/ui/client/lib/components/input/base.controller.js @@ -12,7 +12,13 @@ function BaseInputController (strings) { scope.state._touched = false; scope.state._required = scope.state.required || false; - scope.state._isValid = scope.state._isValid || false; + + if (scope.state.type === 'boolean') { + scope.state._isValid = scope.state._isValid || true; + } else { + scope.state._isValid = scope.state._isValid || false; + } + scope.state._disabled = scope.state._disabled || false; scope.state._activeModel = scope.state._activeModel || '_value'; @@ -59,6 +65,10 @@ function BaseInputController (strings) { scope.state._touched = true; } + if (scope.state.type === 'boolean') { + return { isValid, message }; + } + if (scope.state._required && (!scope.state._value || !scope.state._value[0]) && !scope.state._displayValue) { isValid = false; From 05799d97952e79d1659de68289dcd8f06ec9c0c9 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Wed, 1 Jul 2020 13:41:40 -0400 Subject: [PATCH 2/2] Avoid non-unique field name collisions Custom credentials can have input fields named 'name', 'organization', 'description', etc. Underscore these variables to make collisions less likely to occur. --- .../add-edit-credentials.controller.js | 27 ++++++++++--------- .../add-edit-credentials.view.html | 6 ++--- awx/ui/client/lib/models/Credential.js | 10 +++++++ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/awx/ui/client/features/credentials/add-edit-credentials.controller.js b/awx/ui/client/features/credentials/add-edit-credentials.controller.js index f82fd6e3df..57c8eed1dd 100644 --- a/awx/ui/client/features/credentials/add-edit-credentials.controller.js +++ b/awx/ui/client/features/credentials/add-edit-credentials.controller.js @@ -53,16 +53,19 @@ function AddEditCredentialsController ( vm.form.disabled = !isEditable; } - vm.form.organization._disabled = !isOrgEditableByUser; + vm.form._organization._disabled = !isOrgEditableByUser; // Only exists for permissions compatibility $scope.credential_obj = credential.get(); - vm.form.organization._resource = 'organization'; - vm.form.organization._model = organization; - vm.form.organization._route = 'credentials.edit.organization'; - vm.form.organization._value = credential.get('summary_fields.organization.id'); - vm.form.organization._displayValue = credential.get('summary_fields.organization.name'); - vm.form.organization._placeholder = strings.get('inputs.ORGANIZATION_PLACEHOLDER'); + // Custom credentials can have input fields named 'name', 'organization', + // 'description', etc. Underscore these variables to make collisions + // less likely to occur. + vm.form._organization._resource = 'organization'; + vm.form._organization._model = organization; + vm.form._organization._route = 'credentials.edit.organization'; + vm.form._organization._value = credential.get('summary_fields.organization.id'); + vm.form._organization._displayValue = credential.get('summary_fields.organization.name'); + vm.form._organization._placeholder = strings.get('inputs.ORGANIZATION_PLACEHOLDER'); vm.form.credential_type._resource = 'credential_type'; vm.form.credential_type._model = credentialType; @@ -98,10 +101,10 @@ function AddEditCredentialsController ( vm.form._formName = 'credential'; vm.form.disabled = !credential.isCreatable(); - vm.form.organization._resource = 'organization'; - vm.form.organization._route = 'credentials.add.organization'; - vm.form.organization._model = organization; - vm.form.organization._placeholder = strings.get('inputs.ORGANIZATION_PLACEHOLDER'); + vm.form._organization._resource = 'organization'; + vm.form._organization._route = 'credentials.add.organization'; + vm.form._organization._model = organization; + vm.form._organization._placeholder = strings.get('inputs.ORGANIZATION_PLACEHOLDER'); vm.form.credential_type._resource = 'credential_type'; vm.form.credential_type._route = 'credentials.add.credentialType'; @@ -112,7 +115,7 @@ function AddEditCredentialsController ( $scope.$watch('organization', () => { if ($scope.organization) { - vm.form.organization._idFromModal = $scope.organization; + vm.form._organization._idFromModal = $scope.organization; } }); diff --git a/awx/ui/client/features/credentials/add-edit-credentials.view.html b/awx/ui/client/features/credentials/add-edit-credentials.view.html index 7da2b0e8e1..aa3e581b6d 100644 --- a/awx/ui/client/features/credentials/add-edit-credentials.view.html +++ b/awx/ui/client/features/credentials/add-edit-credentials.view.html @@ -10,9 +10,9 @@ - - - + + + diff --git a/awx/ui/client/lib/models/Credential.js b/awx/ui/client/lib/models/Credential.js index 27b6a04533..6fbce5e141 100644 --- a/awx/ui/client/lib/models/Credential.js +++ b/awx/ui/client/lib/models/Credential.js @@ -27,6 +27,16 @@ function createFormSchema (method, config) { } }); + // Custom credentials can have input fields named 'name', 'organization', + // 'description', etc. Underscore these variables to make collisions + // less likely to occur. + schema._name = schema.name; + schema._organization = schema.organization; + schema._description = schema.description; + delete schema.name; + delete schema.organization; + delete schema.description; + return schema; }