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? ...
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?

 
  1. <?php
  2. /**
  3. * CidadeForm Form
  4. * @author <your name here>
  5. */
  6. class CidadeForm extends TPage
  7. {
  8. protected $form; // form
  9. /**
  10. * Form constructor
  11. * @param $param Request
  12. */
  13. public function __construct( $param )
  14. {
  15. parent::__construct();
  16. // creates the form
  17. $this->form = new TQuickForm('form_Cidade');
  18. $this->form->class = 'tform'; // change CSS class
  19. $this->form = new BootstrapFormWrapper($this->form);
  20. $this->form->style = 'display: table;width:100%'; // change style
  21. // define the form title
  22. $this->form->setFormTitle('Cidade');
  23. // create the form fields
  24. $id = new TEntry('id');
  25. $nome = new TEntry('nome');
  26. $codigo_municipio = new TEntry('codigo_municipio');
  27. $estado_id = new TDBCombo('estado_id', 'erpweb', 'Estado', 'id', 'nome');
  28. // add the fields
  29. $this->form->addQuickField('Id', $id, 100 );
  30. $this->form->addQuickField('Nome', $nome, 200 , new TRequiredValidator);
  31. $this->form->addQuickField('Código de Municipio', $codigo_municipio, 100, new TRequiredValidator );
  32. $this->form->addQuickField('Estado', $estado_id, 100 , new TRequiredValidator);
  33. if (!empty($id))
  34. {
  35. $id->setEditable(FALSE);
  36. }
  37. /** samples
  38. $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  39. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  40. $fieldX->setSize( 100, 40 ); // set size
  41. **/
  42. // create the form actions
  43. $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  44. $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
  45. $this->form->addQuickAction(_t('List'), new TAction(array('CidadeList', 'onReload')), 'fa:table blue');
  46. // vertical box container
  47. $container = new TVBox;
  48. $container->style = 'width: 90%';
  49. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  50. $container->add(TPanelGroup::pack('Title', $this->form));
  51. parent::add($container);
  52. }
  53. /**
  54. * Save form data
  55. * @param $param Request
  56. */
  57. public function onSave( $param )
  58. {
  59. try
  60. {
  61. TTransaction::open('erpweb'); // open a transaction
  62. /**
  63. // Enable Debug logger for SQL operations inside the transaction
  64. TTransaction::setLogger(new TLoggerSTD); // standard output
  65. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  66. **/
  67. $this->form->validate(); // validate form data
  68. $object = new Cidade; // create an empty object
  69. $data = $this->form->getData(); // get form data as array
  70. $object->fromArray( (array) $data); // load the object with data
  71. $object->store(); // save the object
  72. // get the generated id
  73. $data->id = $object->id;
  74. $this->form->setData($data); // fill form data
  75. TTransaction::close(); // close the transaction
  76. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  77. }
  78. catch (Exception $e) // in case of exception
  79. {
  80. new TMessage('error', $e->getMessage()); // shows the exception error message
  81. $this->form->setData( $this->form->getData() ); // keep form data
  82. TTransaction::rollback(); // undo all pending operations
  83. }
  84. }
  85. /**
  86. * Clear form data
  87. * @param $param Request
  88. */
  89. public function onClear( $param )
  90. {
  91. $this->form->clear(TRUE);
  92. }
  93. /**
  94. * Load object to form data
  95. * @param $param Request
  96. */
  97. public function onEdit( $param )
  98. {
  99. try
  100. {
  101. if (isset($param['key']))
  102. {
  103. $key = $param['key']; // get the parameter $key
  104. TTransaction::open('erpweb'); // open a transaction
  105. $object = new Cidade($key); // instantiates the Active Record
  106. $this->form->setData($object); // fill the form
  107. TTransaction::close(); // close the transaction
  108. }
  109. else
  110. {
  111. $this->form->clear(TRUE);
  112. }
  113. }
  114. catch (Exception $e) // in case of exception
  115. {
  116. new TMessage('error', $e->getMessage()); // shows the exception error message
  117. TTransaction::rollback(); // undo all pending operations
  118. }
  119. }
  120. }

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (1)


NR

O tópico abaixo tem o exemplo que você precisa:
https://www.adianti.com.br/forum/pt/view_3650?tbutton-gerando-label