custom profile field: Add at-least-one-choice validation for choice field.

Add validation at-least-one-choice required for every choice type field
in backend.
This commit is contained in:
Yashashvi Dave
2018-08-11 00:09:13 +05:30
committed by Tim Abbott
parent a9c8d9b3d9
commit 2a73b2b805
2 changed files with 8 additions and 0 deletions

View File

@@ -49,6 +49,10 @@ def create_realm_custom_profile_field(request: HttpRequest,
if field_type not in field_types:
return json_error(_("Invalid field type."))
# Choice type field must have at least have one choice
if field_type == CustomProfileField.CHOICE and len(field_data) < 1:
return json_error(_("Field must have at least one choice."))
error = validate_field_data(field_data)
if error:
return json_error(error)