Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tenho no meu DB.py, minhas duas tabelas
- db.define_table("a_cadtiporgao",
- Field("nome", label="Nome"),
- auth.signature,
- format="%(nome)s"
- )
- db.define_table("a_cadorgao",
- Field("codtcm", label="Código do TCM"),
- Field("nome", label="Descrição do Órgão"),
- Field("tipoorg", "reference a_cadtiporgao", label="Tipo do Órgão"),
- Field("cnpj", label="CNPJ"),
- Field("mascara", label="Máscara da Lotação"),
- Field("centralizado", "boolean", label="Marque esta opção quando o Órgão for Centralizador"),
- Field("endereco", label="Endereço"),
- Field("bairro", label="Bairro"),
- Field("cidade", label="Cidade"),
- Field("uf", label="UF"),
- Field("cep", label="CEP"),
- Field("telefone", label="Telefone"),
- Field("obs", label="Observação"),
- auth.signature,
- format="%(nome)s"
- )
- db.a_cadorgao.tipoorg.requires=IS_IN_DB(db,'a_cadtiporgao.id','%(nome)s')
- db.a_cadorgao.cidade.requires=IS_IN_DB(db,'a_cadcidade.id','%(nome)s')
- db.a_cadorgao.uf.requires=IS_IN_SET(ufs)
- db.a_cadorgao.cnpj.requires=IS_CPF_OR_CNPJ()
- no meu controler criei:
- def orgao_new():
- response.view = 'geral/orgao_new.html'
- #Initialize O widget
- add_option = SELECT_OR_ADD_OPTION(form_title="Add new Product Category", controller="geral", function="add_tip_orgao_extra", button_text = "Novo")
- db.a_cadorgao.tipoorg.widget = add_option.widget
- form = SQLFORM(db.a_cadorgao, formstyle="divs", submit_button='Salvar',
- fields=['codtcm', 'nome', 'tipoorg', 'cnpj', 'mascara', 'centralizado', 'endereco'
- , 'bairro', 'cidade', 'uf', 'cep', 'telefone', 'obs'])
- if form.accepts(request.vars, session):
- response.flash = 'Cadastrado realizado com sucesso!'
- redirect(URL(f='orgao_list', args=request.args(0)))
- return dict(form=form)
- def add_tip_orgao_extra():
- #this is the controller function that will appear in our dialog
- form = SQLFORM(db.a_cadtiporgao)
- if form.accepts(request.vars):
- #Successfully added new item
- #do whatever else you may want
- #Then let the user know it worked
- response.flash = T("Added")
- target= request.args[0]
- #close the widget's dialog box
- response.js = '$( "#%s_dialog-form" ).dialog( "close" ); ' %(target)
- #update the options they can select their new category in the main form
- response.js += """$("#%s").append("<option value='%s'>%s</option>");""" \
- % (target, form.vars.id, form.vars.name)
- #and select the one they just added
- response.js += """$("#%s").val("%s");""" % (target, form.vars.id)
- #finally, return a blank form incase for some reason they wanted to add another option
- return form
- elif form.errors:
- #silly user, just send back the form and it'll still be in our dialog box complete with error messages
- return form
- else:
- #hasn't been submitted yet, just give them the fresh blank form
- return form
- na minha view, tem:
- ...
- {{response.files.append("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js")}}
- {{response.files.append("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/smoothness/jquery-ui.css")}}
- ...
- {{=form.custom.begin}}
- <div class='form-group'>
- <label class='control-label col-md-2 col-md-offset-2' autofocus id="control-label" for="tipoorg">Tipo do Órgão: </label>
- {{=form.custom.widget.tipoorg}}
- </div>
- {{=form.custom.end}}
- ...
- quando eu abro a VIEW, so aparece: LOADING ( Novo )
- a palavra NOVO aparece ao receber o focu fica sublinhada, mas nao funciona como um link... nao executa nada
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement