AS
alterar propriedades de componente dinamicamente
Fechado
boa tarde galera, estou tentando alterar os dados de um componente dinamicamente eis a class
quando chamo a função validaCliente, nada acontece
alguem tem uma ideia de cmo fazer?
- <?php
- class frmCliente extends TStandardForm{
- protected $form;
- protected $note;
- protected $panel;
- protected $cnpj;
- protected $inscricao;
- function __construct()
- {
- parent::__construct();
- parent::setDatabase("mysql");
- parent::setActiveRecord("Cliente");
- User::checaLogin('convidado');
- $this->note = new TNotebook(700, 400);
- $this->panel = new TPanel(800,600);
- $this->form = new TQuickForm("Cliente");
- 691 = new THidden('id');
- $nome = new TEntry('razaoSocial');
- $responsavel = new TEntry('responsavel');
- $rua = new TEntry('rua');
- $numero = new TEntry('numero');
- $bairro = new TEntry('bairro');
- $cep = new TEntry('cep');
- $cidade = new TEntry('cidade');
- $uf = new TEntry('uf');
- $telefone = new TEntry('telefone');
- $tipo = new TCombo('tipo');
- $itens = array(
- 'fisico' => 'fisico',
- 'juridico' => 'juridico'
- );
- $tipo->addItems($itens);
- $campos = new TAction(array($this, 'validaCliente'));
- $tipo->setChangeAction($campos);
- $this->cnpj = new TEntry('cnpj');
- $this->inscricao = new TEntry('incricaoEstadual');
- $this->inscricao->setEditable(FALSE);
- $email = new TEntry('email');
- //cep
- $buscaCep = new TAction(array($this, 'onSearch'));
- $cep->setExitAction($buscaCep);
- $telefone->setMask('(99)9999-9999');
- $cep->setMask('99999-999');
- //validação
- $this->inscricao->addValidation('inscricao Estatudal',new TNumericValidator);
- $nome->addValidation('nome',new TRequiredValidator);
- $responsavel->addValidation('sobrenome',new TRequiredValidator);
- $rua->addValidation('rua',new TRequiredValidator);
- $bairro->addValidation('bairro',new TRequiredValidator);
- $cidade->addValidation('cidade',new TRequiredValidator);
- $uf->addValidation('uf',new TRequiredValidator);
- $telefone->addValidation('telefone',new TRequiredValidator);
- $email->addValidation('email', new TEmailValidator());
- $this->form->addQuickField('',691,50);
- $this->form->addQuickField('Nome::',$nome,200);
- $this->form->addQuickField('Responsavel:',$responsavel,200);
- $this->form->addQuickField('CNPJ / CPF:',$this->cnpj,200);
- $this->form->addQuickField('Cliente: ',$tipo,200);
- $this->form->addQuickField('Inscrição Estadual:',$this->inscricao,200);
- $this->form->addQuickField('Cep:',$cep,100);
- $this->form->addQuickField('Rua:',$rua,400);
- $this->form->addQuickField('Numero:', $numero,30);
- $this->form->addQuickField('Bairro:',$bairro,200);
- $this->form->addQuickField('Cidade:',$cidade,200);
- $this->form->addQuickField('UF:',$uf,30);
- $this->form->addQuickField('Telefone:',$telefone,200);
- $this->form->addQuickField('E-mail:',$email,200);
- $this->form->addQuickAction("Save",new TAction(array($this,"onSave")),"ico_save.png");
- $this->form->addQuickAction("Novo",new TAction(array($this,"onEdit")),"ico_new.png");
- $this->form->addQuickAction("Listar",new TAction(array("ClienteView","onReload")),"ico_datagrid.gif");
- $this->note->appendPage('Controle de Cliente',$this->form);
- $this->panel->put($this->note,200, 10);
- parent::add($this->panel);
- }
- /**
- * onSearch()
- * @param string $param 'cep'
- */
- public function onSearch($param){
- $obj = new StdClass;
- $buscaCep = new TCepProgs($param['cep']);
- $obj->rua = $buscaCep->getRua();
- $obj->cidade = $buscaCep->getCidade();
- $obj->bairro = $buscaCep->getBairro();
- $obj->uf = $buscaCep->getUf();
- TForm::sendData('Cliente', $obj);
- }
- public function validaCliente($param){
- if($param['tipo'] == 'juridico'){
- $this->cnpj->addValidation('cpf',new TCNPJValidator());
- $this->cnpj->setMask('99.999.999/9999-99');
- $this->inscricao->setEditable(TRUE);
- }
- else{
- $this->cnpj->addValidation('cpf',new TCPFValidator());
- $this->cnpj->setMask('999.999.999-99');
- $this->inscricao->setEditable(FALSE);
- }
- }
- }
- ?>
quando chamo a função validaCliente, nada acontece
alguem tem uma ideia de cmo fazer?
Olá Alexandre!
Para o seu caso específico sugiro que leia o artigo "Adicionando Validações em Formulários Dinâmicos" de Guilherme faht, que trata justamente desse assunto e posso garantir, por experiência própria que ainda é a melhor solução para esse caso.
Segue o link:
www.adianti.com.br/forum/pt/view_661?adicionando-validacoes-em-formu
como havia te dito acredito que tenha que reinderizar a page de novo acho que é assim não testei....
Alexandre da uma olhada nesse tópico.
https://groups.google.com/forum/#!topic/adianti-tools-pt/aAMNHXvI77E