Exemple #1
0
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(' ')
Exemple #2
0
    def add_allocation_controls(self):
        allocation_controls = self.add_child(FieldSet(self.view, legend_text='Investment allocation'))
        allocation_controls.use_layout(FormLayout())

        if self.form.exception:
            self.layout.add_alert_for_domain_exception(self.form.exception, form=self.form, unique_name='details_section')
        
        total_amount_input = TextInput(self.form, self.investment_order.fields.amount, refresh_widget=self)
        allocation_controls.layout.add_input(total_amount_input)

        amount_or_percentage_radio = RadioButtonSelectInput(self.form, self.investment_order.fields.amount_or_percentage, refresh_widget=self)
        allocation_controls.layout.add_input(amount_or_percentage_radio)
Exemple #3
0
    def __init__(self, view):
        super().__init__(view, 'new_investment_form')
        self.enable_refresh()
        self.use_layout(FormLayout())

        if self.exception:
            self.layout.add_alert_for_domain_exception(self.exception)

        investment_order = InvestmentOrder.for_current_session()
        type_of_investor = self.add_child(FieldSet(view, legend_text='Introduction'))
        type_of_investor.use_layout(FormLayout())

        new_or_existing_radio = RadioButtonSelectInput(self, investment_order.fields.new_or_existing, refresh_widget=self)
        type_of_investor.layout.add_input(new_or_existing_radio)

        if investment_order.new_or_existing:
            self.add_child(InvestorDetailsSection(self, investment_order))
Exemple #4
0
def test_radio_button_label_as_legend(radio_button_fixture):
    """A FormLayout renders a RadioButtonSelectInput in a FieldSet with its label in the Legend."""
    fixture = radio_button_fixture

    form = fixture.form
    form.use_layout(FormLayout())
    inlined_radio = RadioButtonSelectInput(form, fixture.field)
    fixture.form.layout.add_input(inlined_radio)

    field_set = form.children[-1]
    assert isinstance(field_set, FieldSet)
    assert 'form-group' in field_set.get_attribute('class').split(' ')

    [label_widget, radio_input_in_form] = field_set.children
    assert label_widget.tag_name == 'legend'
    assert 'col-form-label' in label_widget.get_attribute('class')
    assert radio_input_in_form is inlined_radio
Exemple #5
0
    def add_allocation_controls(self):
        allocation_controls = self.add_child(
            FieldSet(self.view, legend_text='Investment allocation'))
        allocation_controls.use_layout(FormLayout())

        if self.exception:
            self.add_child(Alert(self.view, str(self.exception), 'warning'))

        total_amount_input = TextInput(self,
                                       self.investment_order.fields.amount,
                                       refresh_widget=self)
        allocation_controls.layout.add_input(total_amount_input)

        amount_or_percentage_radio = RadioButtonSelectInput(
            self,
            self.investment_order.fields.amount_or_percentage,
            refresh_widget=self)
        allocation_controls.layout.add_input(amount_or_percentage_radio)
Exemple #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'))
Exemple #7
0
def test_radio_button_basics(radio_button_fixture):
    """A RadioButtonSelectInput consists of a labelled radio button for each choice, rendered stacked on one another."""
    fixture = radio_button_fixture

    stacked_radio = RadioButtonSelectInput(fixture.form, fixture.field)
    [container] = stacked_radio.children
    [choice1_container, choice2_container] = container.children

    def check_choice_container_details(choice_container, expected_choice_text, expected_button_value):
        choice_container_classes = choice_container.get_attribute('class').split(' ')
        assert 'custom-control' in choice_container_classes
        assert 'custom-radio' in choice_container_classes
        [primitive_radio_button, label] = choice_container.children
        assert label.tag_name == 'label'
        [choice_text_node] = label.children
        assert primitive_radio_button.value == expected_button_value
        assert choice_text_node.value == expected_choice_text

    check_choice_container_details(choice1_container, 'One', '1')
    check_choice_container_details(choice2_container, 'Two', '2')