GG
Adicionar um botão para novo estado no form cadastro de cidade
Preciso criar um botão para novo estado no form de cadastro de cidade ao lado do TDBCombo $estado_id = new TDBCombo('estado_id', 'erpweb', 'Estado', 'id', 'nome');
Como faço?
Como faço?
- <?php
- /**
- * CidadeForm Form
- * @author <your name here>
- */
- class CidadeForm extends TPage
- {
- protected $form; // form
-
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
-
- // creates the form
- $this->form = new TQuickForm('form_Cidade');
- $this->form->class = 'tform'; // change CSS class
- $this->form = new BootstrapFormWrapper($this->form);
- $this->form->style = 'display: table;width:100%'; // change style
-
- // define the form title
- $this->form->setFormTitle('Cidade');
-
- // create the form fields
- $id = new TEntry('id');
- $nome = new TEntry('nome');
- $codigo_municipio = new TEntry('codigo_municipio');
- $estado_id = new TDBCombo('estado_id', 'erpweb', 'Estado', 'id', 'nome');
- // add the fields
- $this->form->addQuickField('Id', $id, 100 );
- $this->form->addQuickField('Nome', $nome, 200 , new TRequiredValidator);
- $this->form->addQuickField('Código de Municipio', $codigo_municipio, 100, new TRequiredValidator );
- $this->form->addQuickField('Estado', $estado_id, 100 , new TRequiredValidator);
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
-
- /** samples
- $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( 100, 40 ); // set size
- **/
-
- // create the form actions
- $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
- $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
- $this->form->addQuickAction(_t('List'), new TAction(array('CidadeList', 'onReload')), 'fa:table blue');
-
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add(TPanelGroup::pack('Title', $this->form));
-
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('erpweb'); // open a transaction
-
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
-
- $this->form->validate(); // validate form data
-
- $object = new Cidade; // create an empty object
- $data = $this->form->getData(); // get form data as array
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
-
- // get the generated id
- $data->id = $object->id;
-
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
-
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
-
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear(TRUE);
- }
-
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('erpweb'); // open a transaction
- $object = new Cidade($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
O tópico abaixo tem o exemplo que você precisa:
https://www.adianti.com.br/forum/pt/view_3650?tbutton-gerando-label