form->setData para TDBSeekButton Quando clico em minha datagri eu carrego meu formulario porem o campo que é preenchido pelo TDBSeekButton não é preenchido! ...
AM
form->setData para TDBSeekButton  
Fechado
Quando clico em minha datagri eu carrego meu formulario porem o campo que é preenchido pelo TDBSeekButton não é preenchido!

 
  1. <?php
  2. /**
  3. * ContratoForm Registration
  4. * @author <your name here>
  5. */
  6. class ContratoForm extends TPage
  7. {
  8. protected $form; // form
  9. /**
  10. * Class constructor
  11. * Creates the page and the registration form
  12. */
  13. function __construct()
  14. {
  15. parent::__construct();
  16. // creates the form
  17. $this->form = new TForm('form_Contrato');
  18. $this->form->class = 'tform'; // CSS class
  19. // add a table inside form
  20. $table = new TTable;
  21. $table-> width = '100%';
  22. $this->form->add($table);
  23. // add a row for the form title
  24. $row = $table->addRow();
  25. $row->class = 'tformtitle'; // CSS class
  26. $row->addCell( new TLabel('Contrato') )->colspan = 2;
  27. // create the form fields
  28. 1429 = new TEntry('id');
  29. $cliente_id = new ">TDBSeekButton('cliente_id', 'sim', 'form_Contrato', 'Cliente', 'razao', 'cliente_id', 'nome_cliente');
  30. $nome_cliente = new TEntry('nome_cliente');
  31. $numero_contrato = new TEntry('numero_contrato');
  32. $data_inicio = new TDate('data_inicio');
  33. $status = new TRadioGroup('status');
  34. //outros
  35. 1429->setEditable(false);
  36. $nome_cliente->setEditable(false);
  37. //populando o radio status
  38. $status->setLayout('horizontal');
  39. $items_status = array();
  40. $items_status['1'] = 'Ativo';
  41. $items_status['2'] = 'Fechado';
  42. $status->addItems($items_status);
  43. // define the sizes
  44. 1429->setSize(50);
  45. $cliente_id->setSize(50);
  46. $nome_cliente->setSize(200);
  47. $numero_contrato->setSize(200);
  48. $data_inicio->setSize(100);
  49. $status->setSize(200);
  50. // validations
  51. $cliente_id->addValidation('Cliente', new TRequiredValidator);
  52. $numero_contrato->addValidation('N° Contrato', new TRequiredValidator);
  53. $data_inicio->addValidation('Data de Inicio', new TRequiredValidator);
  54. $status->addValidation('Status', new TRequiredValidator);
  55. // add one row for each form field
  56. $table->addRowSet( new TLabel('ID:'), 1429 );
  57. $table->addRowSet( $label_cliente_id = new TLabel('Cliente:'), array($cliente_id,$nome_cliente) );
  58. $label_cliente_id->setFontColor('#FF0000');
  59. $table->addRowSet( $label_numero_contrato = new TLabel('N° Contrato:'), $numero_contrato );
  60. $label_numero_contrato->setFontColor('#FF0000');
  61. $table->addRowSet( $label_data_inicio = new TLabel('Data de Inicio:'), $data_inicio );
  62. $label_data_inicio->setFontColor('#FF0000');
  63. $table->addRowSet( $label_status = new TLabel('Status:'), $status );
  64. $label_status->setFontColor('#FF0000');
  65. $this->form->setFields(array(1429,$cliente_id,$nome_cliente,$numero_contrato,$data_inicio,$status));
  66. // create the form actions
  67. $save_button = TButton::create('save', array($this, 'onSave'), _t('Save'), 'ico_save.png');
  68. $new_button = TButton::create('new', array($this, 'onEdit'), _t('New'), 'ico_new.png');
  69. $list_button = TButton::create('list', array('ContratoList', 'onReload'), _t('List'),'ico_datagrid.png');
  70. $this->form->addField($save_button);
  71. $this->form->addField($new_button);
  72. $this->form->addField($list_button);
  73. $buttons_box = new THBox;
  74. $buttons_box->add($save_button);
  75. $buttons_box->add($new_button);
  76. $buttons_box->add($list_button);
  77. // add a row for the form action
  78. $row = $table->addRow();
  79. $row->class = 'tformaction'; // CSS class
  80. $row->addCell($buttons_box)->colspan = 2;
  81. $container = new TTable;
  82. $container->style = 'width: 80%';
  83. $container->addRow()->addCell(new TXMLBreadCrumb('menu.xml','ContratoList'));
  84. $container->addRow()->addCell($this->form);
  85. // add the form to the page
  86. parent::add($container);
  87. }
  88. /**
  89. * method onSave()
  90. * Executed whenever the user clicks at the save button
  91. */
  92. function onSave()
  93. {
  94. try
  95. {
  96. TTransaction::open('sim'); // open a transaction
  97. // get the form data into an active record Contrato
  98. $object = $this->form->getData('Contrato');
  99. $this->form->validate(); // form validation
  100. $object->store(); // stores the object
  101. $this->form->setData($object); // keep form data
  102. TTransaction::close(); // close the transaction
  103. // shows the success message
  104. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  105. }
  106. catch (Exception $e) // in case of exception
  107. {
  108. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  109. $this->form->setData( $this->form->getData() ); // keep form data
  110. TTransaction::rollback(); // undo all pending operations
  111. }
  112. }
  113. /**
  114. * method onEdit()
  115. * Executed whenever the user clicks at the edit button da datagrid
  116. */
  117. function onEdit($param)
  118. {
  119. try
  120. {
  121. if (isset($param['key']))
  122. {
  123. $key=$param['key']; // get the parameter $key
  124. TTransaction::open('sim'); // open a transaction
  125. $object = new Contrato($key); // instantiates the Active Record
  126. $this->form->setData($object); // fill the form
  127. TTransaction::close(); // close the transaction
  128. }
  129. else
  130. {
  131. $this->form->clear();
  132. }
  133. }
  134. catch (Exception $e) // in case of exception
  135. {
  136. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  137. TTransaction::rollback(); // undo all pending operations
  138. }
  139. }
  140. }
  141. </code>

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


FC


 
  1. <?php
  2. function onEdit($param)
  3. {
  4. try
  5. {
  6. if (isset($param['key']))
  7. {
  8. $key=$param['key']; // get the parameter $key
  9. TTransaction::open('sim'); // open a transaction
  10. $object = new Contrato($key); // instantiates the Active Record
  11. $object->nome_cliente = <b>cliente</b>->nome_cliente; //é preciso fazer esta associação o no seu model
  12. $this->form->setData($object); // fill the form
  13. TTransaction::close(); // close the transaction
  14. }
  15. else
  16. {
  17. $this->form->clear();
  18. }
  19. }
  20. catch (Exception $e) // in case of exception
  21. {
  22. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  23. TTransaction::rollback(); // undo all pending operations
  24. }
  25. }
  26. }
  27. ?>
PD

Augusto,

Se você fizer um método get_nome_cliente() na model Contrato, também resolverá.

Att,