예제 #1
0
def test_checkbox_with_inline_layout(web_fixture, choices_fixture):
    """PrimitiveCheckboxInputs can be rendered inlined with each other by using the ChoicesLayout with the inline=True setting."""
    fixture = choices_fixture

    inlined_container = Div(web_fixture.view).use_layout(ChoicesLayout(inline=True))
    inlined_container.layout.add_choice(PrimitiveCheckboxInput(fixture.form, fixture.boolean_field))

    assert 'custom-control-inline' in inlined_container.children[0].get_attribute('class').split(' ')
예제 #2
0
파일: test_form.py 프로젝트: diopib/reahl
def choices_layout(fixture):
    """A ChoicesLayout can be used to add a PrimitiveCheckboxInput inlined or stacked."""
    stacked_container = Div(fixture.view).use_layout(ChoicesLayout())
    stacked_container.layout.add_choice(
        PrimitiveCheckboxInput(fixture.form, fixture.field))

    tester = WidgetTester(stacked_container)
    vassert(fixture.input_is_wrapped_in_label(tester))
    vassert(fixture.main_element(tester).tag == 'div')
    vassert(fixture.main_element(tester).attrib['class'] == 'checkbox')

    inlined_container = Div(fixture.view).use_layout(
        ChoicesLayout(inline=True))
    inlined_container.layout.add_choice(
        PrimitiveCheckboxInput(fixture.form, fixture.field))

    tester = WidgetTester(inlined_container)
    vassert(fixture.input_is_wrapped_in_label(tester))
    vassert(fixture.main_element(tester).tag == 'label')
    vassert(fixture.main_element(tester).attrib['class'] == 'checkbox-inline')
예제 #3
0
파일: test_form.py 프로젝트: xmonader/reahl
def test_radio_button_layout(radio_button_fixture):
    """To make a RadioButtonSelectInput inline, supply a suitable ChoicesLayout"""
    fixture = radio_button_fixture

    radio_input = RadioButtonSelectInput(
        fixture.form,
        fixture.field,
        contents_layout=ChoicesLayout(inline=True))
    assert radio_input.contents_layout.inline

    choice_container = radio_input.children[0].children[0]
    assert 'custom-control-inline' in choice_container.get_attribute(
        'class').split(' ')
예제 #4
0
파일: test_form.py 프로젝트: diopib/reahl
def layout_of_radio_button_input(fixture):
    """The PrimitiveRadioButtonInputs inside a RadioButtonInput are also laid out using a ChoicesLayout."""
    stacked_radio = RadioButtonInput(fixture.form, fixture.field)

    tester = WidgetTester(stacked_radio)
    vassert(fixture.input_is_wrapped_in_label(tester))
    vassert(fixture.main_element(tester).tag == 'div')
    vassert(fixture.main_element(tester).attrib['class'] == 'radio')

    inlined_radio = RadioButtonInput(fixture.form,
                                     fixture.field,
                                     button_layout=ChoicesLayout(inline=True))

    tester = WidgetTester(inlined_radio)
    vassert(fixture.input_is_wrapped_in_label(tester))
    vassert(fixture.main_element(tester).tag == 'label')
    vassert(fixture.main_element(tester).attrib['class'] == 'radio-inline')
예제 #5
0
def test_choices_layout_applied_to_checkbox(web_fixture, choices_fixture):
    """A ChoicesLayout lays out PrimitiveCheckboxInputs inside a Label containing the Field label, such that they will be stacked."""
    fixture = choices_fixture

    stacked_container = Div(web_fixture.view).use_layout(ChoicesLayout())
    stacked_container.layout.add_choice(PrimitiveCheckboxInput(fixture.form, fixture.boolean_field))

    stacked_container_classes = stacked_container.children[0].get_attribute('class').split(' ')
    assert 'custom-control' in stacked_container_classes
    assert 'custom-checkbox' in stacked_container_classes

    [checkbox_input, label] = stacked_container.children[0].children
    [description_widget] = label.children
    assert label.tag_name == 'label'

    assert checkbox_input.html_representation.input_type == 'checkbox'
    assert description_widget.value == 'field'
예제 #6
0
    def __init__(self, view, event_channel_name):
        super().__init__(view, event_channel_name)
        self.use_layout(FormLayout())
        model_object = ModelObject()
        self.layout.add_input(
            TextInput(self, model_object.fields.text_input_field))
        self.layout.add_input(
            CheckboxInput(self, model_object.fields.boolean_field))
        self.layout.add_input(
            PasswordInput(self, model_object.fields.password_field))
        self.layout.add_input(
            TextArea(self,
                     model_object.fields.text_area_field,
                     rows=5,
                     columns=60))
        self.layout.add_input(
            SelectInput(self, model_object.fields.choice_field))
        self.layout.add_input(
            SelectInput(self, model_object.fields.multi_choice_field))
        self.layout.add_input(
            CheckboxInput(self,
                          model_object.fields.another_multi_choice_field))
        self.layout.add_input(
            RadioButtonSelectInput(self,
                                   model_object.fields.radio_choice_field,
                                   contents_layout=ChoicesLayout(inline=True)))
        self.layout.add_input(
            TextInput(self, model_object.fields.fuzzy_date_field, fuzzy=True))
        self.layout.add_input(TextInput(
            self,
            model_object.fields.text_input_without_label,
            placeholder=True),
                              hide_label=True)
        self.layout.add_input(
            CueInput(TextInput(self, model_object.fields.cue_field),
                     P(view, text='This is a cue')))
        self.define_event_handler(model_object.events.do_something)

        self.add_child(
            ButtonInput(self,
                        model_object.events.do_something,
                        style='primary'))
예제 #7
0
def test_choice_disabled_state(web_fixture, disabled_scenarios):
    """Visible cues are inserted to indicate that inputs are disabled. """
    fixture = disabled_scenarios

    form = Form(web_fixture.view, 'test')
    field = fixture.field
    field.bind('field', fixture)

    container = Div(web_fixture.view).use_layout(ChoicesLayout())
    container.layout.add_choice(PrimitiveCheckboxInput(form, field))

    [checkbox_container] = container.children
    [checkbox_input, label] = checkbox_container.children
    checkbox_container_classes = checkbox_container.get_attribute('class').split(' ')
    if fixture.expects_disabled_class:
        assert 'disabled' in checkbox_container_classes
        assert checkbox_input.html_representation.get_attribute('disabled') == 'disabled'
    else:
        assert 'disabled' not in checkbox_container_classes
        with expected(KeyError):
            checkbox_input.html_representation.get_attribute('disabled')