Form with inputs in line
def create_inline_form(self, view): class MyForm(Form): def __init__(self, view): super().__init__(view, 'AnInlineform') model_object = ModelObject() self.use_layout(InlineFormLayout()) self.layout.add_input( TextInput(self, model_object.fields.text_input_field, placeholder='Jane Doe'), hide_label=False) self.layout.add_input( PasswordInput(self, model_object.fields.password_field), hide_label=True) self.define_event_handler(model_object.events.do_something) self.add_child(ButtonInput(self, model_object.events.do_something, style='primary')) return MyForm(view)
Form with inputs grid arranged
def create_grid_form(self, view): class MyForm(Form): def __init__(self, view): super().__init__(view, 'aGridForm') model_object = ModelObject() self.use_layout(GridFormLayout(ResponsiveSize(lg=4), ResponsiveSize(lg=8))) self.layout.add_input(TextInput(self, model_object.fields.text_input_field), help_text='This help displays under for grid') self.layout.add_input(PasswordInput(self, model_object.fields.password_field)) return MyForm(view)
Form with file upload input and progress bar
def create_file_upload_form(self, view): class DomainObject: files = [] fields = ExposedNames() fields.files = lambda i: FileField(allow_multiple=True, label='Attached files') events = ExposedNames() events.submit = lambda i: Event(label='Submit') domain_object = DomainObject() class FileUploadForm(Form): def __init__(self, view): super().__init__(view, 'myfileform') self.use_layout(FormLayout()) self.layout.add_input(FileUploadInput(self, domain_object.fields.files)) self.define_event_handler(domain_object.events.submit) self.add_child(Button(self, domain_object.events.submit)) return FileUploadForm(view)
Form with text-ish inputs
def create_text_input_form(self, view): class MyForm(Form): def __init__(self, view): super().__init__(view, 'myform1') model_object = ModelObject() self.use_layout(FormLayout()) self.layout.add_input(TextInput(self, model_object.fields.text_input_field), help_text='some help') self.layout.add_input(TextInput(self, model_object.fields.email_input_field), help_text='tab out first to see the validation message appear') 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.layout.add_input(TextInput(self, model_object.fields.fuzzy_date_field, fuzzy=True)) 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.define_event_handler(model_object.events.do_something) self.add_child(ButtonInput(self, model_object.events.do_something, style='primary')) return MyForm(view)
Form with InputGroups
def create_group_input_form(self, view): class MyForm(Form): def __init__(self, view): super().__init__(view, 'myform2') model_object = ModelObject() self.use_layout(FormLayout()) self.layout.add_input(InputGroup('raw before widget', TextInput(self, model_object.fields.another_text_input_field, placeholder='This is an inputgroup'), 'raw after widget')) self.layout.add_input(InputGroup(P(view, text='before widget'), TextInput(self, model_object.fields.yet_another_text_input_field, placeholder='This is an another inputgroup'), P(view, text='after widget'))) self.define_event_handler(model_object.events.do_something) self.add_child(ButtonInput(self, model_object.events.do_something, style='primary')) return MyForm(view)
Form with selection inputs
def create_choices_input_form(self, view): class MyForm(Form): def __init__(self, view): super().__init__(view, 'myform3') model_object = ModelObject() self.use_layout(FormLayout()) self.layout.add_input(CheckboxInput(self, model_object.fields.boolean_field)) 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(RadioButtonSelectInput(self, model_object.fields.radio_choice_field, contents_layout=ChoicesLayout(inline=True))) self.layout.add_input(RadioButtonSelectInput(self, model_object.fields.another_radio_choice_field, contents_layout=ChoicesLayout())) self.layout.add_input(CheckboxInput(self, model_object.fields.another_multi_choice_field)) return MyForm(view)
Form with fieldset
def create_fieldset_form(self, view): class MyForm(Form): def __init__(self, view): super().__init__(view, 'myform4') model_object = ModelObject() self.use_layout(FormLayout()) grouped_inputs = FieldSet(view, legend_text='Leave a comment') grouped_inputs.use_layout(FormLayout()) text_input = TextInput(self, model_object.fields.yet_yet_another_text_input_field) grouped_inputs.layout.add_input(text_input) password_input = PasswordInput(self, model_object.fields.another_password_field) grouped_inputs.layout.add_input(password_input) self.add_child(grouped_inputs) self.define_event_handler(model_object.events.do_something) self.add_child(ButtonInput(self, model_object.events.do_something, style='primary')) return MyForm(view)