Conheça as melhorias da versão 8.0, 8.1, 8.2!
Clique aqui para saber mais
Ocultar campos no form Estou tentando ocultar alguns campos dentro do form através de um evento. Vi que com o TQuickForm::hideField dá pra ocultar campos dentro do form, mas para isso tem que usar o TQuickForm, Como eu estou usando o TForm com TNotebook, li uma postagem do D'aloglio que posso usar o TQuickForm dentro de um TForm, mas não está funcionando. separei um pedaço do código pra mostrar a voçês, talve...
DD
Ocultar campos no form  
Estou tentando ocultar alguns campos dentro do form através de um evento. Vi que com o TQuickForm::hideField dá pra ocultar campos dentro do form, mas para isso tem que usar o TQuickForm, Como eu estou usando o TForm com TNotebook, li uma postagem do D'aloglio que posso usar o TQuickForm dentro de um TForm, mas não está funcionando.

separei um pedaço do código pra mostrar a voçês, talvez alquem possa me dizer o que está errado, ou sugerir outra maneira de eu fazer.

$this->form = new TForm('form_name');
$this->form->class = 'tform'; // CSS class

$table = new TTable;

$this->notebook = new TNotebook(850, 650);
$this->notebook->appendPage('Notebook', $table);

$this->form->add($this->notebook);

$tipo = new TDBCombo('tipo','database','Tabela','codigo','descricao','codigo');
$cnpj = new TEntry('cnpj');
$cpf = new TEntry('cpf');
$identificacao = new TEntry('identificacao');

// define the action for tab_tp_importador
$change_action = new TAction(array($this, 'onTipoAction'));
$tipo->setChangeAction($change_action);

// create the form using TQuickForm class
$this->form_tipo = new TQuickForm('form_tipo');
$this->form_tipo->class = 'tform';
$this->form_tipo->setFormTitle('Tipo');
$row = $table->addRow();
$row->addCell($this->form_tipo);

$this->form_tipo->addQuickFields('Tipo', array($tipo) );
$this->form_tipo->addQuickField('CNPJ', $cnpj);
$this->form_tipo->addQuickField('CPF', $cpf);
$this->form_tipo->addQuickField('Identificação', $identificacao);

$this->formFields = array($tipo, $cnpj, $cpf, $identificacao);
$this->form->setFields( $this->formFields );

$vbox = new TVBox;
$vbox->add(new TXMLBreadCrumb('menu.xml', 'FormList'));

$vbox->add($this->form);

// add the form inside the page
parent::add($vbox);

}

public static function onTipoAction($param)
{

$obj = new StdClass;
if ($param['tipo'] == '1'){
TQuickForm::showField('form_tipo', 'cnpj');
TQuickForm::hideField('form_tipo', 'cpf');
TQuickForm::hideField('form_tipo', 'identificacao');
$obj->import_cpf = '';
$obj->import_md_identificacao = '';
}
if ($param['tipo'] == '2' OR $param['tipo'] == '3'){
TQuickForm::showField('form_tipo', 'cpf');
TQuickForm::hideField('form_tipo', 'cnpj');
TQuickForm::hideField('form_tipo', 'identificacao');
$obj->import_cnpj = '';
$obj->import_md_identificacao = '';
}
if ($param['tipo'] == '4' OR $param['tipo'] == '5'){
TQuickForm::showField('form_tipo', 'identificacao');
TQuickForm::hideField('form_tipo', 'cnpj');
TQuickForm::hideField('form_tipo', 'cpf');
$obj->import_cpf = '';
$obj->import_cnpj = '';
}
TForm::sendData('form_tipo', $obj);
}

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)


NR

Denilson, você tem o link dessa postagem do Pablo? Não entendi como isso funcionaria, visto que teríamos um formulário dentro do outro.

Sem usar a TQuickForm você poderia fazer o seguinte:
 
  1. <?php
  2. $row = $table->addRowSet(new TLabel('Tipo'), $tipo);
  3. $row->class = 'tformrow';
  4. $row = $table->addRowSet(new TLabel('CNPJ'), $cnpj);
  5. $row->class = 'tformrow';
  6. $row = $table->addRowSet(new TLabel('CPF'), $cpf);
  7. $row->class = 'tformrow';
  8. $row = $table->addRowSet(new TLabel('Identificação'), $identificacao);
  9. $row->class = 'tformrow';
  10. ?>

As funções showField e hideField usam o atributo 'class=tformrow' para identificar quais linhas devem ser exibidas/ocultadas.

Obs: lembre de alterar o nome do formulário na função onTipoAction para 'form_name' no lugar de 'form_tipo'
DD

Obrigado pela dica Nataniel.

consegui ocultar através do Jquery, descrevo abaixo como ficou:

$subtable = new TTable;
$frame->add($subtable);
$subtable->addRowSet( new TLabel('Tipo'), array($tipo) );
$row_cnpj = $subtable->addRowSet( new TLabel('CNPJ'), array($cnpj) );
$row_cnpj->id = 'cnpj';
$row_cpf = $subtable->addRowSet( new TLabel('CPF'), array($cpf) );
$row_cpf->id = 'cpf';
$row_id = $subtable->addRowSet( new TLabel('Identificação'), array($identificacao) );
$row_id->id = 'id';

na função do evento onExit ficou assim:

public static function onTipoAction($param)
{
$obj = new StdClass;
if ($param['tipo'] == '1'){
TScript::create("$('[id=cnpj]').show();");
TScript::create("$('[id=cpf]').hide();");
TScript::create("$('[id=id]').hide();");
$obj->cpf = '';
$obj->identificacao = '';
}
if ($param['tipo'] == '2'){
TScript::create("$('[id=cnpj]').hide();");
TScript::create("$('[id=cpf]').show();");
TScript::create("$('[id=id]').hide();");
$obj->cnpj = '';
$obj->identificacao = '';
}
if ($param['tipo'] == '3'){
TScript::create("$('[id=cnpj]').hide();");
TScript::create("$('[id=cpf]').hide();");
TScript::create("$('[id=id]').show();");
$obj->cpf = '';
$obj->cnpj = '';
}
TForm::sendData('form', $obj);
}