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!
- <?php
- /**
- * ContratoForm Registration
- * @author <your name here>
- */
- class ContratoForm extends TPage
- {
- protected $form; // form
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TForm('form_Contrato');
- $this->form->class = 'tform'; // CSS class
- // add a table inside form
- $table = new TTable;
- $table-> width = '100%';
- $this->form->add($table);
- // add a row for the form title
- $row = $table->addRow();
- $row->class = 'tformtitle'; // CSS class
- $row->addCell( new TLabel('Contrato') )->colspan = 2;
- // create the form fields
- 1429 = new TEntry('id');
- $cliente_id = new ">TDBSeekButton('cliente_id', 'sim', 'form_Contrato', 'Cliente', 'razao', 'cliente_id', 'nome_cliente');
- $nome_cliente = new TEntry('nome_cliente');
- $numero_contrato = new TEntry('numero_contrato');
- $data_inicio = new TDate('data_inicio');
- $status = new TRadioGroup('status');
- //outros
- 1429->setEditable(false);
- $nome_cliente->setEditable(false);
- //populando o radio status
- $status->setLayout('horizontal');
- $items_status = array();
- $items_status['1'] = 'Ativo';
- $items_status['2'] = 'Fechado';
- $status->addItems($items_status);
- // define the sizes
- 1429->setSize(50);
- $cliente_id->setSize(50);
- $nome_cliente->setSize(200);
- $numero_contrato->setSize(200);
- $data_inicio->setSize(100);
- $status->setSize(200);
- // validations
- $cliente_id->addValidation('Cliente', new TRequiredValidator);
- $numero_contrato->addValidation('N° Contrato', new TRequiredValidator);
- $data_inicio->addValidation('Data de Inicio', new TRequiredValidator);
- $status->addValidation('Status', new TRequiredValidator);
- // add one row for each form field
- $table->addRowSet( new TLabel('ID:'), 1429 );
- $table->addRowSet( $label_cliente_id = new TLabel('Cliente:'), array($cliente_id,$nome_cliente) );
- $label_cliente_id->setFontColor('#FF0000');
- $table->addRowSet( $label_numero_contrato = new TLabel('N° Contrato:'), $numero_contrato );
- $label_numero_contrato->setFontColor('#FF0000');
- $table->addRowSet( $label_data_inicio = new TLabel('Data de Inicio:'), $data_inicio );
- $label_data_inicio->setFontColor('#FF0000');
- $table->addRowSet( $label_status = new TLabel('Status:'), $status );
- $label_status->setFontColor('#FF0000');
- $this->form->setFields(array(1429,$cliente_id,$nome_cliente,$numero_contrato,$data_inicio,$status));
- // create the form actions
- $save_button = TButton::create('save', array($this, 'onSave'), _t('Save'), 'ico_save.png');
- $new_button = TButton::create('new', array($this, 'onEdit'), _t('New'), 'ico_new.png');
- $list_button = TButton::create('list', array('ContratoList', 'onReload'), _t('List'),'ico_datagrid.png');
- $this->form->addField($save_button);
- $this->form->addField($new_button);
- $this->form->addField($list_button);
- $buttons_box = new THBox;
- $buttons_box->add($save_button);
- $buttons_box->add($new_button);
- $buttons_box->add($list_button);
- // add a row for the form action
- $row = $table->addRow();
- $row->class = 'tformaction'; // CSS class
- $row->addCell($buttons_box)->colspan = 2;
- $container = new TTable;
- $container->style = 'width: 80%';
- $container->addRow()->addCell(new TXMLBreadCrumb('menu.xml','ContratoList'));
- $container->addRow()->addCell($this->form);
- // add the form to the page
- parent::add($container);
- }
- /**
- * method onSave()
- * Executed whenever the user clicks at the save button
- */
- function onSave()
- {
- try
- {
- TTransaction::open('sim'); // open a transaction
- // get the form data into an active record Contrato
- $object = $this->form->getData('Contrato');
- $this->form->validate(); // form validation
- $object->store(); // stores the object
- $this->form->setData($object); // keep form data
- TTransaction::close(); // close the transaction
- // shows the success message
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button da datagrid
- */
- function onEdit($param)
- {
- try
- {
- if (isset($param['key']))
- {
- $key=$param['key']; // get the parameter $key
- TTransaction::open('sim'); // open a transaction
- $object = new Contrato($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
- </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
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4
Quero me inscrever agora!
Augusto,
Se você fizer um método get_nome_cliente() na model Contrato, também resolverá.
Att,