def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Field.checkboxes("method", legend_size=Size.MEDIUM, small=True), Button("submit", "Submit"), )
def test_override_default_legend_size(): """Verify a default legend size can be overridden on the field.""" form = CheckboxesForm() form.helper = FormHelper() form.helper.legend_size = Size.MEDIUM form.helper.layout = Layout( Field.checkboxes("method", legend_size=Size.LARGE)) assert parse_form(form) == parse_contents(RESULT_DIR, "override_legend_size.html")
def field_to_layout(field_name, field): """ Converts fields into their GDS styled counterparts. If the counterpart is unknown, return the field_name as default """ if isinstance(field, forms.CharField): return Field.text(field_name, label_size=Size.SMALL) if isinstance(field, forms.ChoiceField): return Field.checkboxes(field_name, legend_size=Size.SMALL) return field_name
def test_choices(): """Verify that hints are displayed.""" form = CheckboxesChoiceForm(initial={"method": ["email", "text"]}) form.helper = FormHelper() form.helper.layout = Layout(Field.checkboxes("method")) assert parse_form(form) == parse_contents(RESULT_DIR, "choices.html")
def test_initial_attributes(): """Verify all the gds attributes are displayed.""" form = CheckboxesForm(initial={"method": ["email", "text"]}) form.helper = FormHelper() form.helper.layout = Layout(Field.checkboxes("method")) assert parse_form(form) == parse_contents(RESULT_DIR, "initial.html")