def __init__(self, view): super(CommentForm, self).__init__(view, 'myform') comment = Comment() layout = ColumnLayout( ColumnOptions('left', size=ResponsiveSize(lg=6)), ColumnOptions('right', size=ResponsiveSize(lg=6))) # .add_child() returns the added child here: row = self.add_child(Div(view).use_layout(layout)) left_column = row.layout.columns['left'] # ... and .use_layout() returns the Widget it is called on section = Div(view).use_layout(FormLayout()) left_column.add_child(section) email_input = TextInput(self, comment.fields.email_address) section.layout.add_input(email_input) inline_section = Div(view).use_layout(InlineFormLayout()) left_column.add_child(inline_section) text_input = TextInput(self, comment.fields.text) inline_section.layout.add_input(text_input) right_column = row.layout.columns['right'] right_column.add_child( LiteralHTML.from_restructured_text( view, ''' This form has two columns. Inputs go into the left one and this text into the right one. Some inputs are stacked and others are inlined. Arbitrarily complicated layouts can be created like this.'''))
def __init__(self, view): super().__init__(view, 'dynamic_content_error_form') self.use_layout(FormLayout()) self.calculator = Calculator.for_current_session() try: self.enable_refresh( on_refresh=self.calculator.events.inputs_changed) except DomainException as ex: self.layout.add_alert_for_domain_exception(ex) controls = self.add_child( FieldSet(view).use_layout(InlineFormLayout())) self.add_inputs(controls) self.display_result(controls)
def __init__(self, view): super().__init__(view, 'my_cool_form') calculator = Calculator.for_current_session() self.enable_refresh(on_refresh=calculator.events.input_changed) grouped_inputs = self.add_child( FieldSet(view, legend_text='Calculator')) grouped_inputs.use_layout(InlineFormLayout()) grouped_inputs.layout.add_input( TextInput(self, calculator.fields.operandA, refresh_widget=self)).use_layout( MarginLayout(2, right=True)) grouped_inputs.layout.add_input( SelectInput(self, calculator.fields.operandB, refresh_widget=self)) self.add_child(P(self.view, text='Sum: %s' % calculator.sum))
def inline_form(self): self.layout = InlineFormLayout() self.expected_html = '<div class="form-inline"></div>'
def __init__(self, view): super().__init__(view, 'aform') self.use_layout(InlineFormLayout()) self.layout.add_input(TextInput( self, fixture.domain_object.fields.an_attribute), help_text='some help')