RB
TFieldList não é adiciona ao formulário
Olá, a todos,
Estou tendo um problema ao tentar adicionar o componente TFieldList ao formulário, porém não estou tendo sucesso.
Aguém consegue me auxliar.
Segue código fonte abaixo e imagem com a descrição do erro.
Estou tendo um problema ao tentar adicionar o componente TFieldList ao formulário, porém não estou tendo sucesso.
Aguém consegue me auxliar.
Segue código fonte abaixo e imagem com a descrição do erro.
- <?php
- class ClienteFisico extends TPage
- {
- private $form;
- private $db = 'teste';
- private $contato_list;
- private $telefone_list;
- private $contacts;
- private $telefones;
- /**
- * Class constructor
- * Creates the page
- */
- public function __construct()
- {
- parent::__construct();
- parent::include_css('app/resources/form.css');
- $this->form = new BootstrapFormBuilder('form_fisico');
- $this->form->setFormTitle('');
- $this->form->setFieldSizes('100%');
- $this->form->style = 'border 1px solid #546';
- $this->form->generateAria(); // automatic aria-label
- $this->form->appendPage('Dados Pessoais');
- $id = new TEntry('id');
- $nome = new TEntry('nome');
- $cpf = new TEntry('cpf');
- $rg = new TEntry('rg');
- $uf_rg = new TEntry('uf_rg');
- $data_emissao_rg = new TDate('data_emissao_rg');
- $data_nascimento = new TDate('data_nascimento');
- $genero_id = new TCombo('genero_id');
- $estado_civil_id = new TDBUniqueSearch('estado_civil_id', $this->db, 'EstadoCivil', 'id', 'nome');
- $homephone = new TEntry('homephone');
- $naturalidade = new TEntry('naturalidade');
- $street = new TEntry('logradouro');
- $number = new TEntry('numero');
- $complemento = new TEntry('complemento');
- $neighborhood = new TEntry('bairro');
- $localidade = new TEntry('localidade');
- $municipio = new TEntry('municipio');
- $state = new TEntry('uf');
- $cep = new TEntry('cep');
- $id->setEditable(false);
- $genero_id->addItems(['1' => 'Masculino', '2' => 'Feminino']);
- //formata mascaras
- $cpf->setMask('999.999.999-99');
- $cep->setMask('99.999-999', true);
- $data_nascimento->setMask('dd/mm/yyyy');
- $data_emissao_rg->setMask('dd/mm/yyyy');
- $homephone->setMask('(99)9999-99999');
- $data_nascimento->setDatabaseMask('yyyy-mm-dd');
- $data_emissao_rg->setDatabaseMask('yyyy-mm-dd');
- $row = $this->form->addFields( [ new TLabel('Código'),$id ],
- [ new TLabel('Nome'),$nome ],
- [ new TLabel('Data de Nascimento'),$data_nascimento ],
- [ new TLabel('Genero'),$genero_id],
- [ new TLabel('Estado Cívil'),$estado_civil_id]
- );
- $row->layout = ['col-sm-1','col-sm-5','col-sm-2','col-sm-2','col-sm-2'];
- $row = $this->form->addFields( [ new TLabel('RG'),$rg ],
- [ new TLabel(_t('State')),$uf_rg],
- [ new TLabel('Data de Emissão'),$data_emissao_rg ],
- [ new TLabel('CPF'),$cpf],
- [ new TLabel('Título Eleitor'),$homephone ],
- [ new TLabel('Naturalidade'),$naturalidade ]);
- $row->layout = ['col-sm-2', 'col-sm-1', 'col-sm-2', 'col-sm-2', 'col-sm-2', 'col-sm-2'];
- $label2 = new TLabel(_t('Address'), '#5A73DB', 12, '');
- $label2->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%';
- $this->form->addContent( [$label2] );
- $row = $this->form->addFields(
- [ new TLabel('Cep'),$cep ] ,
- [ new TLabel(_t('Street')),$street ],
- [ new TLabel(_t('Number')),$number ],
- [ new TLabel(_t('complement')),$complemento ]
- );
- $row->layout = ['col-sm-2', 'col-sm-5', 'col-sm-2','col-sm-3'];
- $row = $this->form->addFields( [ new TLabel(_t('Neighborhood')),$neighborhood ],
- [ new TLabel(_t('County')),$municipio ],
- [ new TLabel(_t('City')),$localidade ],
- [ new TLabel(_t('State')),$state ]
- );
- $row->layout = ['col-sm-4','col-sm-4', 'col-sm-3','col-sm-1'];
- $this->form->appendPage('Contatos');
- /*
- //Cria campos dos telefones
- $ddi = new TEntry('ddi[]');
- $ddi->setMask('99');
- $ddi->setSize('100%');
- $ddi->style = 'text-align: right';
- $ddd = new TEntry('ddd[]');
- $ddd->setMask('999');
- $ddd->setSize('100%');
- $ddd->style = 'text-align: right';
- // create detail fields
- $tipo_telefone_id = new TDBUniqueSearch('tipo_telefone_id[]', '$db', 'TipoTelefone', 'id', 'nome');
- $tipo_telefone_id->setMinLength(1);
- $tipo_telefone_id->setSize('100%');
- $tipo_telefone_id->setMask('{nome} ({id})');
- $numero_telefone = new TEntry('numero_telefone[]');
- $numero_telefone->setMask('9999-9999');
- $numero_telefone->setSize('100%');
- $numero_telefone->style = 'text-align: right';
- //$numero_telefone->setChangeAction(new TAction(array($this, 'onChangeProduct')));
- $this->form->addField($ddi);
- $this->form->addField($ddd);
- $this->form->addField($tipo_telefone_id);
- $this->form->addField($numero_telefone);
- // detail
- $this->telefone_list = new TFieldList;
- $this->telefone_list->generateAria();
- $this->telefone_list->addField( '<b>DDI</b>',$ddi ,['width' => '50px']);
- $this->telefone_list->addField( '<b>DDD</b>',$ddd , ['width' => '50px']);
- $this->telefone_list->addField( '<b>Tipo</b>',$tipo_telefone_id, ['width' => '42%']);
- $this->telefone_list->addField( '<b>Número</b>',$numero_telefone,['width' => '42%']);
- $this->telefone_list-> width = '100%';
- $this->telefone_list->enableSorting();
- // add field list to the form
- //$this->form->addContent( [$this->telefone_list] );
- $row = $this->form->addFields([$this->telefone_list]);
- $row->layout = ['col-sm-12' ];
- */
- //cria campos dos contatos
- $nome_contato = new TEntry('nome_contato[]');
- $nome_contato->setSize('100%');
- $nome_contato->style = 'text-align: right';
- // create detail fields
- $tipo_contato_id = new TDBUniqueSearch('tipo_contato_id[]', '$db', 'TipoContato', 'id', 'nome');
- $tipo_contato_id->setMinLength(1);
- $tipo_contato_id->setSize('100%');
- $tipo_contato_id->setMask('{nome} ({id})');
- //$parentesco_id = new TEntry('parentesco_id[]');
- //$parentesco_id->setSize('100%');
- //$parentesco_id->style = 'text-align: right';
- $this->form->addField($nome_contato);
- $this->form->addField($tipo_contato_id);
- //$this->form->addField($parentesco_id);
- // detail
- $this->contato_list = new TFieldList;
- $this->contato_list->addField( '<b>DDI</b>',$nome_contato ,['width' => '50px']);
- $this->contato_list->addField( '<b>DDD</b>',$tipo_contato_id , ['width' => '50px']);
- //$this->contato_list->addField( '<b>Grau Parentesco</b>',$parentesco_id, ['width' => '42%']);
- $this->contato_list-> width = '100%';
- $this->contato_list->enableSorting();
- //$this->form->addContent( [ new TLabel('Contatos') ], [ $this->contacts ] );
- $row = $this->form->addFields([$this->contato_list]);
- $row->layout = ['col-sm-12' ];
- $row = $this->form->addFields( [ new TLabel('Pai'), $t1 = new TEntry('pai') ],
- [ new TLabel('Mãe'), $t2 = new TEntry('mae') ] );
- $row->layout = ['col-sm-4', 'col-sm-8' ];
- $row = $this->form->addFields( [ new TLabel('Test3'), $text = new TText('text') ] );
- $row->layout = ['col-sm-12' ];
- $cpf->addValidation('CPF', new TRequiredValidator);
- $data_nascimento->addValidation('Data de Nascimento', new TRequiredValidator);
- $genero_id->addValidation('Genero', new TRequiredValidator);
- $estado_civil_id->addValidation('Estado Cívil', new TRequiredValidator);
- $cep->addValidation('CEP', new TRequiredValidator);
- $this->form->addAction(_t('Send'), new TAction(array($this, 'onSend')), 'far:check-circle green');
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- $vbox->add(new TXMLBreadCrumb('menu.xml', 'DataGridClienteFisico'));
- $vbox->add($this->form);
- parent::add($vbox);
- }
- /**
- * Post data
- */
- public function onSend($param)
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open($this->db);
- $this->form->validate(); // run form validation
- $data = $this->form->getData(); // get form data as array
- $pessoa = new Pessoa; // create an empty object
- $pessoa->fromArray( (array) $data); // load the object with data
- $pessoa->tipo_pessoa_id = 1;
- $pessoa->situacao_id = 1;
- $pessoa->store(); // save the object
- if($pessoa)
- {
- if( !empty($param['tipo_contato_id']) AND is_array($param['tipo_contato_id']) )
- {
- foreach( $param['tipo_contato_id'] as $row => $tipo_contato_id)
- {
- if ($tipo_contato_id)
- {
- $contato = new Contato;
- $contato->pessoa_id = $pessoa->id;
- $contato->system_unit_id = TSession::getValue('userunitids');
- $contato->tipo_contato_id = $param['tipo_contato_id'][$row];
- $contato->nome = $param['nome_contato'][$row];
- $contato->atualizacao = date('Y-m-d H:m:s:s');
- // add the contact to the customer
- $pessoa->addContact($contato);
- }
- }
- }
- $cpf = preg_replace("/[^0-9]/", "", $data->cpf);
- //echo $cpf;
- $fisica = new Fisica;
- $fisica->pessoa_id = $pessoa->id;
- $fisica->nome = $data->nome;
- $fisica->data_nascimento = $data->data_nascimento;
- $fisica->genero_id = $data->genero_id;
- $fisica->estado_civil_id = $data->estado_civil_id;
- $fisica->cpf = preg_replace("/[^0-9]/", "", $data->cpf);
- $fisica->rg = preg_replace("/[^0-9]/", "", $data->rg);
- $fisica->uf_rg = $data->uf_rg;
- $fisica->data_emissao_rg = $data->data_emissao_rg;
- $fisica->orgao_expedidor_rg = $data->uf_rg;
- $fisica->titulo_eleitor = $data->homephone;
- $fisica->uf_titulo_eleitor = $data->uf_rg;
- $fisica->naturalidade = $data->naturalidade;
- $fisica->pai = $data->pai;
- $fisica->mae = $data->mae;
- $fisica->store();
- }
- // fill the form with the active record data
- $data->id = $pessoa->id;
- $this->form->setData($data);
- TTransaction::close(); // close the transaction
- // shows the success message
- new TMessage('info', 'Record saved');
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Executed whenever the user clicks at the edit button da datagrid
- */
- public function onEdit($param)
- {
- try
- {
- if (isset($param['pessoa_id']))
- {
- TTransaction::open($this->db);
- $key = $param['pessoa_id'];
- $object = Fisica::find($key);
- $object->id = $object->pessoa_id;
- $object->id = $object->pessoa_id;
- $this->form->setData($object); // fill the form with the active record data
- // load the contacts (composition)
- $contacts = $object->pessoa->pessoa_vinculo->getcontatos();
- print_r($contacts);
- if ($contacts)
- {
- $this->contacts->addHeader();
- foreach ($contacts as $contact)
- {
- $contact_detail = new stdClass;
- $contact_detail->tipo_contato_id = $contact->tipo_contato_id;
- $contact_detail->nome_contato = $contact->nome;
- $this->contacts->addDetail($contact_detail);
- }
- $this->contacts->addCloneAction();
- }
- else
- {
- $this->onClear($param);
- }
- }
- TTransaction::close(); // close transaction
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- /**
- * Clear form
- */
- public function onClear($param)
- {
- $this->form->clear();
- $this->contacts->addHeader();
- $this->contacts->addDetail( new stdClass );
- $this->contacts->addCloneAction();
- }
- }
Parece que faltou a linha de inclusão no form:
Felipe Cortez: Resolvido.
Muito obrigado pela dica, funcionou perfeito.
Nada como um olhar externo.
Valeu.