{parts/gtag_head.html} {parts/gtag_body.html}
Conheça  A Ferramenta LowCode mais moderna e veloz para desenvolvimento PHP: Adianti Creator
Problemas ao usar Form com Notebook Oi. Estou tendo problemas em acessar os dados de um formulário dentro de notebook e a manipulação de botões: Mais precisamente, pq essa linha de código não funciona?? TButton::disableField('form_Teste', 'save'); ...
GE
Problemas ao usar Form com Notebook  
Fechado
Oi.
Estou tendo problemas em acessar os dados de um formulário dentro de notebook e a manipulação de botões:

Mais precisamente, pq essa linha de código não funciona??
TButton::disableField('form_Teste', 'save');

 
  1. <?php
  2. class CommonPage extends TPage
  3. {
  4. protected $form; // form
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->form = new TForm('form_Teste');
  9. // creates the notebook
  10. $notebook = new TNotebook(400,250);
  11. // creates the containers for each notebook page
  12. $page1 = new TTable;
  13. $page2 = new TPanel(370,180);
  14. $page3 = new TTable;
  15. $this->form->add($notebook);
  16. // adds two pages in the notebook
  17. $notebook->appendPage('Basic data', $page1);
  18. $notebook->appendPage('Other data', $page2);
  19. $notebook->appendPage('Other note', $page3);
  20. // create the form fields
  21. $field1 = new TEntry('field1');
  22. $field2 = new TEntry('field2');
  23. $field3 = new TEntry('field3');
  24. $field4 = new TEntry('field4');
  25. $field5 = new TEntry('field5');
  26. $field6 = new TEntry('field6');
  27. $field7 = new TEntry('field7');
  28. $field8 = new TEntry('field8');
  29. $field9 = new TEntry('field9');
  30. $field10= new TEntry('field10');
  31. // change the size for some fields
  32. $field1->setSize(100);
  33. $field2->setSize(80);
  34. $field3->setSize(150);
  35. $field6->setSize(80);
  36. $field7->setSize(80);
  37. $field8->setSize(80);
  38. $field9->setSize(80);
  39. $field10->setSize(80);
  40. ## fields for the page 1 ##
  41. // add a row for a label
  42. $row=$page1->addRow();
  43. $cell=$row->addCell(new TLabel('<b>Table Layout</b>'));
  44. $cell->valign = 'top';
  45. $cell->colspan=2;
  46. // adds a row for a field
  47. $row=$page1->addRow();
  48. $row->addCell(new TLabel('Field1:'));
  49. $row->addCell($field1);
  50. // adds a row for a field
  51. $row=$page1->addRow();
  52. $row->addCell(new TLabel('Field2:'));
  53. $cell = $row->addCell($field2);
  54. $cell->colspan=3;
  55. // adds a row for a field
  56. $row=$page1->addRow();
  57. $row->addCell(new TLabel('Field3:'));
  58. $cell = $row->addCell($field3);
  59. $cell->colspan=3;
  60. // adds a row for a field
  61. $row=$page1->addRow();
  62. $row->addCell(new TLabel('Field4:'));
  63. $row->addCell($field4);
  64. // adds a row for a field
  65. $row=$page1->addRow();
  66. $row->addCell(new TLabel('Field5:'));
  67. $row->addCell($field5);
  68. ## fields for the page 2 ##
  69. $page2->put(new TLabel('<b>Panel Layout</b>'), 4, 4);
  70. $page2->put(new TLabel('Field6'), 20, 30);
  71. $page2->put(new TLabel('Field7'), 50, 60);
  72. $page2->put(new TLabel('Field8'), 80, 90);
  73. $page2->put(new TLabel('Field9'), 110, 120);
  74. $page2->put(new TLabel('Field10'),140, 150);
  75. $page2->put($field6, 120, 30);
  76. $page2->put($field7, 150, 60);
  77. $page2->put($field8, 180, 90);
  78. $page2->put($field9, 210, 120);
  79. $page2->put($field10,240, 150);
  80. ## fields for the page 3 ##
  81. // creates the notebook
  82. $subnotebook = new TNotebook(250, 160);
  83. $subnotebook->appendPage('new page1', new TLabel('test1'));
  84. $subnotebook->appendPage('new page2', new TText('test2'));
  85. $row = $page3->addRow();
  86. $row->addCell($subnotebook);
  87. // create the form actions
  88. $save_button = TButton::create('save', array($this, 'onSave'), _t('Save'), 'ico_save.png');
  89. $delete_button = TButton::create('delete', array($this, 'onDelete'), _t('Delete'), 'ico_delete.png');
  90. $new_button = TButton::create('new', array($this, 'onEdit'), _t('New'), 'ico_new.png');
  91. // $list_button = TButton::create('list', array('FilmeList', 'onReload'), _t('List'), 'ico_datagrid.png');
  92. $this->form->addField($save_button);
  93. $this->form->addField($delete_button);
  94. $this->form->addField($new_button);
  95. // $this->form->addField($list_button);
  96. $subtable = new TTable;
  97. $row = $subtable->addRow();
  98. $row->addCell($save_button);
  99. $row->addCell($delete_button);
  100. $row->addCell($new_button);
  101. // $row->addCell($list_button);
  102. $vbox = new TVBox;
  103. $vbox->add($notebook);
  104. $vbox->add($subtable);
  105. TButton::disableField('form_Teste', 'save');
  106. parent::add($vbox);
  107. }
  108. /**
  109. * method onSave()
  110. * Executed whenever the user clicks at the save button
  111. */
  112. function onSave()
  113. {
  114. try
  115. {
  116. TTransaction::open('filme'); // open a transaction
  117. // get the form data into an active record Filme
  118. $object = $this->form->getData('Filme');
  119. $object->dataVisualizacao = $this->formatDate($object->dataVisualizacao);
  120. if($object->genero_list)
  121. {
  122. foreach($object->genero_list as $genero_id)
  123. {
  124. $object->addGenero(new Genero($genero_id));
  125. }
  126. }
  127. $this->form->validate(); // form validation
  128. $object->store(); // stores the object
  129. $object->dataVisualizacao = $this->formatDateBR($object->dataVisualizacao);
  130. $this->form->setData($object); // keep form data
  131. // $this->upload($object->imagem, 'teste');
  132. TTransaction::close(); // close the transaction
  133. // shows the success message
  134. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  135. }
  136. catch (Exception $e) // in case of exception
  137. {
  138. new TMessage('error', '<b>Erros encontrados:</b> <br />' . $e->getMessage()); // shows the exception error message
  139. $this->form->setData( $this->form->getData() ); // keep form data
  140. TTransaction::rollback(); // undo all pending operations
  141. }
  142. if ($object instanceof Filme)
  143. {
  144. $source_file = 'tmp/'.$object->photo_path;
  145. $target_file = 'app/images/foto/' . $object->id.'.png';
  146. $finfo = new finfo(FILEINFO_MIME_TYPE);
  147. if (file_exists($source_file) AND ($finfo->file($source_file) == 'image/png' OR $finfo->file($source_file) == 'image/jpeg'))
  148. {
  149. // move to the target directory
  150. rename($source_file, $target_file);
  151. }
  152. else
  153. {
  154. if($object->photo_path)
  155. {
  156. new TMessage('error', '<b>Arquivo de imagem inálido</b> <br />'); // shows the exception error message
  157. }
  158. }
  159. }
  160. }
  161. /**
  162. * method onEdit()
  163. * Executed whenever the user clicks at the edit button da datagrid
  164. */
  165. function onEdit($param)
  166. {
  167. try
  168. {
  169. if (isset($param['key']))
  170. {
  171. $key=$param['key']; // get the parameter $key
  172. TTransaction::open('filme'); // open a transaction
  173. $object = new Filme($key); // instantiates the Active Record
  174. if(!$object->dataVisualizacao)
  175. {
  176. $object->dataVisualizacao = $object->datavisualizacao;
  177. }
  178. $object->dataVisualizacao = $this->formatDateBR($object->dataVisualizacao);
  179. $generos = $object->getGeneros();
  180. $genero_list = array();
  181. if($generos)
  182. {
  183. foreach ($generos as $genero)
  184. {
  185. $genero_list[] = $genero->id;
  186. }
  187. }
  188. $object->genero_list = $genero_list;
  189. $this->form->setData($object); // fill the form
  190. TTransaction::close(); // close the transaction
  191. }
  192. else
  193. {
  194. $object = new StdClass;
  195. $object->nota = 1;
  196. $this->form->clear();
  197. $this->form->setData($object); // fill the form
  198. }
  199. }
  200. catch (Exception $e) // in case of exception
  201. {
  202. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  203. TTransaction::rollback(); // undo all pending operations
  204. }
  205. }
  206. /**
  207. * method onDelete()
  208. * executed whenever the user clicks at the delete button
  209. * Ask if the user really wants to delete the record
  210. */
  211. function onDelete($param)
  212. {
  213. // define the delete action
  214. $action = new TAction(array($this, 'Delete'));
  215. $action->setParameters($param); // pass the key parameter ahead
  216. // shows a dialog to the user
  217. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  218. }
  219. /**
  220. * method Delete()
  221. * Delete a record
  222. */
  223. function Delete($param)
  224. {
  225. try
  226. {
  227. $key=$param['id']; // get the parameter $key
  228. TTransaction::open('filme'); // open a transaction with database
  229. $object = new Filme($key, FALSE); // instantiates the Active Record
  230. $object->delete(); // deletes the object from the database
  231. TTransaction::close(); // close the transaction
  232. $object = new StdClass;
  233. $object->nota = 1;
  234. $this->form->clear();
  235. $this->form->setData($object); // fill the form
  236. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted')); // success message
  237. }
  238. catch (Exception $e) // in case of exception
  239. {
  240. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  241. TTransaction::rollback(); // undo all pending operations
  242. }
  243. }
  244. public function formatDate($date)
  245. {
  246. $dt = explode('/', $date);
  247. $retorno = $dt[2].'-'.$dt[1].'-'.$dt[0];
  248. return $retorno;
  249. }
  250. public function formatDateBR($date)
  251. {
  252. $dt = explode('-', $date);
  253. $retorno = $dt[2].'/'.$dt[1].'/'.$dt[0];
  254. return $retorno;
  255. }
  256. }
  257. ?>



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 (3)


FC

Ue esse recurso para desabilitar deveria estar dentro de uma função estática não solta na parte de criação da page vc deveria montar a page já com o botão desabilitado com o setEnabled = False

Depois se houver necessidade ativar o mesmo num evento posterior.
GE

Oi Felipe.
Quando utilizo o onExitAction eu utilizo classe estática.

Mas nesse caso não funciona. Acredito que deva ser algo no meu empacotamento de form, table e notebook.
Tenho outras páginas que desabilito o botão no constructor e conforme as ações do formulario eu habilito ele.
GE

Realmente o problema era o empacotamento, sendo que no código os botões estavam fora do form.

$vbox = new TVBox; $vbox->add($notebook); $vbox->add($subtable); $this->form->add($vbox); TButton::disableField('form_Teste', 'save'); parent::add($this->form);