def login_form(): form = FORM(id="meu-forme", action="#", method="GET", target="_blank") form <= LABEL('seu nome', For='nome', name="nome") form <= INPUT(id='nome') form <= BR() form <= LABEL('sua senha', For='senha', senha="senha") form <= INPUT(id='senha', type='password', required=True) form <= BR() form <= INPUT(id='submit', type='submit') return form
def render(self): txt = TxtManager() todo = List() app = group( DIV(Class="container d-flex flex-column justify-content-center"), group(DIV(Class="container-sm m-3"), [ DIV(style={"margin": "10px"}), txt.render(), H1("Todo List With Breact"), DIV(style={"margin": "10px"}), todo.render(), group(DIV(Class="row"), [ group(DIV(Class="col-sm form-group"), [ LABEL("Enter Title", to="inputt", Class="form-label"), title := INPUT( id="inputt", type="text", Class="form-control"), ]), description := group(DIV(Class="col-sm form-group"), [ LABEL("Enter Description", to="inputts", Class="form-label"), TEXTAREA( id="inputts", type="text", Class="form-control") ]), ]), btn := BUTTON("Submit please", Class="btn btn-primary m-2"), DIV(style={"margin": "40px"}) ])) @bind(title, "keyup") def updateTitle(e): txt.setState({"title": e.target.value}) @bind(description, "keyup") def updateDesc(e): txt.setState({"description": e.target.value}) @bind(btn, "click") def submit(e): submission = { "title": txt.state["title"], "description": txt.state["description"] } todo.state["items"].append(submission) todo.setState({"items": todo.state["items"]}) return app # document["root"] <= Main().render()
def make_table(data, w, section): t = TABLE() tr = TR() for c, d in enumerate(data, 1): if isinstance(d, str): tr <= TD(LABEL(INPUT(type='checkbox', Id=d, Class='flag_val', data_id=d, data_type=section) + d)) else: tr <= TD(LABEL(INPUT(type='checkbox', Id=d[0], Class='flag_val', data_id=d[1], data_type=section) + d[1])) if not c % w: t <= tr tr = TR() if c % w: t <= tr return t
def login_form(): form = FORM(Class='form login-form', id="meu-forme", action="#", method="GET", target="blank") form <= H2('Meu formulário') form <= LABEL('seu nome', For='nome') form <= INPUT(id='nome', name='nome', required=True) form <= BR() form <= LABEL('sua senha', For='senha') form <= INPUT(id='senha', type='password', name='senha', required=True) form <= BR() form <= INPUT(id='submit', type='submit') document <= form
def _create_input( name, type, label='', Class='', text='', value='', required=False, ): """ Cria um input completo. Baseados nas implementações do CSS, insere uma div `form-group` um input e um label Args: ---- name: id do input type: tipo do input label: texto do label Class: classe CSS text: texto do componente value: valur do componente required: input validator required Retorna uma div do grupo com o elemto inserido na div. Example: ------- >>> _create_input('nome', 'text', 'Seu nome') <div class="form-group"> <label for="nome"> Seu nome </label> <input id="nome", type="text"> </div> """ d = DIV(Class='form-group') d <= LABEL(f'{label}: ' if label else '', For=name, id=f'l{name}') d <= INPUT( text, id=name, name=name, type=type, Class=Class, value=value, required=required, ) return d
def make_table(m_data, w, header=False, item_class=''): t = TABLE() tr = TR() for c, d in enumerate(m_data, 1): if isinstance(d, str): new_id = f"{item_class + '_' if item_class else ''}{d}" for a, b in [(' ', '_'), ('\'', '_'), ('+', '_')]: new_id = new_id.replace(a, b) tr <= TD( LABEL( INPUT( type='checkbox', Id=new_id, Class=f'save {"header" if header else "flag_val"}', data_id=f"{item_class + '_' if item_class else ''}{d}") + d)) if not c % w: t <= tr tr = TR() if c % w: t <= tr return t
def cadastro_pessoa(): form = FORM(id="meu-form", action="#", method="get", target="_blank") form <= LABEL('Nome', id='nome') form <= INPUT(id='Nome', name='Nome') form <= BR() form <= LABEL('CPF', id='cPF') form <= INPUT(id='CPF', type='password', name='CPF') form <= BR() form <= LABEL('Telefone', id='telefone') form <= INPUT(id='Telefone', type='password', name='Telefone') form <= BR() form <= LABEL('Adicionar', id='add') form <= BUTTON(id='submit', name='submit', type='button') form <= BR() form <= LABEL('Mostrar lista de pessoas:', id='stud_list') form <= BUTTON(id='all_students', name='students list', type='button') form <= BR() form <= H1('Deletar pessoa do banco de dados') form <= LABEL('ID da pessoa', id='delete_stud') form <= INPUT(id='id', name='ID') form <= BR() form <= LABEL('Deletar: ', id='delete_stud') form <= BUTTON(id='delete', name='delete', type='button') form <= H1('Adicionar curso a pessoa') form <= LABEL('ID da pessoa', id='id_pessoa') form <= INPUT(id='id_pcurso', name='ID') form <= BR() form <= LABEL('Curso', id='curso_type') form <= INPUT(id='curso', name='Curso') form <= BR() form <= LABEL('Adicionar curso: ', id='add_pessoa_curso') form <= BUTTON(id='add_pc', name='add_pc', type='button') form <= BR() form <= LABEL('Mostrar cursos: ', id='cursos') form <= BUTTON(id='show_curso', name='show_cursos', type='button') #open('GET', 'http://127.0.0.1:5000/alunos/add', True) #get('http://127.0.0.1:5000/alunos/add') return form