def get_select_field(answer, label, guidance, error_messages):
validate_with = get_mandatory_validator(answer, error_messages, 'MANDATORY_RADIO')
# We use a custom coerce function to avoid a defect where Python NoneType
# is coerced to the string 'None' which clashes with legitimate Radio field
# values of 'None'; i.e. there is no way to differentiate between the user
# not providing an answer and them selecting the 'None' option otherwise.
# https://github.com/ONSdigital/eq-survey-runner/issues/1013
# See related WTForms PR: https://github.com/wtforms/wtforms/pull/288
return SelectField(
label=label,
description=guidance,
choices=build_choices(answer['options']),
validators=validate_with,
coerce=_coerce_str_unless_none,
)
评论列表
文章目录