Make field validation to be conditional.

Introduce new field attribute 'enabled' - true by default, but if it
is false, then the field won't be validated, only coerced to Python
type. This actually solves the issue with hidden (and disabled) fields
which don't validate and prevent proceeding to next step.

Change-Id: Ie57fa4731792ed1e44e9f61fa5cb6a16ddaf3109
Fixes: bug MRN-883
This commit is contained in:
Timur Sufiev 2013-09-12 15:12:03 +04:00
parent 38fe87c113
commit 7a3fe8b194
3 changed files with 15 additions and 7 deletions

View File

@ -38,7 +38,14 @@ def with_request(func):
return update
class CustomPropertiesField(object):
class CustomPropertiesField(forms.Field):
def clean(self, value):
"""Skip all validators if field is disabled."""
if getattr(self, 'enabled', True):
return super(CustomPropertiesField, self).clean(value)
else:
return super(CustomPropertiesField, self).to_python(value)
@classmethod
def push_properties(cls, kwargs):
props = {}

View File

@ -253,7 +253,8 @@ class ServiceConfigurationForm(UpdatableFieldsForm):
raise forms.ValidationError(error_messages)
for name, field in self.fields.iteritems():
if isinstance(field, fields.PasswordField):
if (isinstance(field, fields.PasswordField) and
getattr(field, 'enabled', True)):
field.compare(name, cleaned_data)
if hasattr(field, 'postclean'):

View File

@ -58,18 +58,18 @@ forms:
- name: domainAdminUserName
type: string
label: Active Directory User
required: {YAQL: $.serviceConfiguration.externalAD}
enabled: {YAQL: $.serviceConfiguration.externalAD}
regexpValidator: '^[-\w]+$'
errorMessages:
invalid: 'Just letters, numbers, underscores and hyphens are allowed.'
invalid: Just letters, numbers, underscores and hyphens are allowed.
- name: domainAdminPassword
type: password
label: Active Directory Password
required: {YAQL: $.serviceConfiguration.externalAD}
enabled: {YAQL: $.serviceConfiguration.externalAD}
- name: domain
type: domain
label: Domain
required: {YAQL: not $.serviceConfiguration.externalAD}
enabled: {YAQL: not $.serviceConfiguration.externalAD}
description: >-
Service can be joined to the Active Directory domain. If you want to
create an AD domain create the AD Service first.
@ -89,7 +89,7 @@ forms:
label: SA Password
description: Set system administrator password for the MS SQL Server.
helpText: SQL server System Administrator account
required: {YAQL: $.serviceConfiguration.mixedModeAuth}
enabled: {YAQL: $.serviceConfiguration.mixedModeAuth}
- clusterConfiguration:
fields:
- name: clusterIP