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

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 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,