Lançado Adianti Framework 7.6!
Clique aqui para saber mais
alterar propriedades de componente dinamicamente boa tarde galera, estou tentando alterar os dados de um componente dinamicamente eis a class ...
AS
alterar propriedades de componente dinamicamente  
Fechado
boa tarde galera, estou tentando alterar os dados de um componente dinamicamente eis a class


  1. <?php
  2. class frmCliente extends TStandardForm{
  3.     
  4.     
  5.        
  6.  
  7.     protected $form;
  8.        protected $note;
  9.        protected $panel;
  10.        protected $cnpj;
  11.        protected $inscricao;
  12.                
  13.     function __construct()
  14.     {
  15.         parent::__construct();
  16.         
  17.         
  18.         
  19.      parent::setDatabase("mysql");
  20.         parent::setActiveRecord("Cliente");
  21.         
  22.           User::checaLogin('convidado');
  23.          
  24.             $this->note = new TNotebook(700400);
  25.         $this->panel = new TPanel(800,600);
  26.           
  27.         $this->form = new TQuickForm("Cliente");
  28.         
  29.          691 = new THidden('id');
  30.         
  31.         $nome = new TEntry('razaoSocial');
  32.         
  33.         $responsavel = new TEntry('responsavel');
  34.         $rua = new TEntry('rua');
  35.           $numero = new TEntry('numero');
  36.         $bairro = new TEntry('bairro');
  37.         $cep = new TEntry('cep');
  38.         $cidade = new TEntry('cidade');
  39.         $uf = new TEntry('uf');
  40.         $telefone = new TEntry('telefone');
  41.      
  42.         $tipo = new TCombo('tipo');
  43.         
  44.         $itens = array(
  45.             'fisico' => 'fisico',
  46.             'juridico' => 'juridico'
  47.         );
  48.         $tipo->addItems($itens);
  49.         
  50.         $campos = new TAction(array($this'validaCliente'));
  51.         $tipo->setChangeAction($campos);
  52.                 
  53.         $this->cnpj = new TEntry('cnpj');
  54.           $this->inscricao = new TEntry('incricaoEstadual');
  55.           $this->inscricao->setEditable(FALSE);
  56.         $email = new TEntry('email');
  57.       
  58.         //cep
  59.         
  60.          $buscaCep = new TAction(array($this'onSearch'));
  61.         $cep->setExitAction($buscaCep);
  62.         
  63.      
  64.         
  65.         $telefone->setMask('(99)9999-9999');
  66.         $cep->setMask('99999-999');
  67.        
  68.         //validação
  69.         $this->inscricao->addValidation('inscricao Estatudal',new TNumericValidator);
  70.    
  71.            $nome->addValidation('nome',new TRequiredValidator);
  72.            $responsavel->addValidation('sobrenome',new TRequiredValidator);
  73.            $rua->addValidation('rua',new TRequiredValidator);
  74.            $bairro->addValidation('bairro',new TRequiredValidator);
  75.            $cidade->addValidation('cidade',new TRequiredValidator);
  76.            $uf->addValidation('uf',new TRequiredValidator);
  77.            $telefone->addValidation('telefone',new TRequiredValidator);
  78.          $email->addValidation('email', new TEmailValidator());
  79.         
  80.         
  81.      
  82.         $this->form->addQuickField('',691,50);    
  83.         $this->form->addQuickField('Nome::',$nome,200);
  84.         $this->form->addQuickField('Responsavel:',$responsavel,200);
  85.         $this->form->addQuickField('CNPJ / CPF:',$this->cnpj,200);
  86.             $this->form->addQuickField('Cliente: ',$tipo,200);
  87.        $this->form->addQuickField('Inscrição Estadual:',$this->inscricao,200);
  88.         
  89.         $this->form->addQuickField('Cep:',$cep,100);
  90.         $this->form->addQuickField('Rua:',$rua,400);
  91.         $this->form->addQuickField('Numero:'$numero,30);
  92.         $this->form->addQuickField('Bairro:',$bairro,200);
  93.         $this->form->addQuickField('Cidade:',$cidade,200);
  94.         $this->form->addQuickField('UF:',$uf,30);
  95.         $this->form->addQuickField('Telefone:',$telefone,200);
  96.         $this->form->addQuickField('E-mail:',$email,200);
  97.     
  98.         
  99.         
  100.         
  101.         $this->form->addQuickAction("Save",new TAction(array($this,"onSave")),"ico_save.png");
  102.         $this->form->addQuickAction("Novo",new TAction(array($this,"onEdit")),"ico_new.png");
  103.         $this->form->addQuickAction("Listar",new TAction(array("ClienteView","onReload")),"ico_datagrid.gif");
  104.         
  105.         
  106.         
  107.          $this->note->appendPage('Controle de Cliente',$this->form);
  108.         $this->panel->put($this->note,20010);
  109.         parent::add($this->panel);
  110.     
  111.     }
  112.     
  113.     
  114.    
  115.     
  116.         /**
  117.      * onSearch()
  118.      * @param string $param 'cep'
  119.      */
  120.   
  121.     
  122.     public function onSearch($param){
  123.     
  124.       $obj = new StdClass;
  125.         $buscaCep = new TCepProgs($param['cep']);
  126.       
  127.         $obj->rua $buscaCep->getRua();
  128.         $obj->cidade     $buscaCep->getCidade();
  129.         $obj->bairro     $buscaCep->getBairro();
  130.         $obj->uf         $buscaCep->getUf(); 
  131.         TForm::sendData('Cliente'$obj);
  132.         }
  133.     
  134.     
  135.      public function validaCliente($param){
  136.     
  137.    
  138.     
  139.     if($param['tipo'] == 'juridico'){
  140.          $this->cnpj->addValidation('cpf',new TCNPJValidator());
  141.          $this->cnpj->setMask('99.999.999/9999-99');
  142.          $this->inscricao->setEditable(TRUE);
  143.      
  144.     }
  145.     else{
  146.         
  147.         $this->cnpj->addValidation('cpf',new TCPFValidator());
  148.         $this->cnpj->setMask('999.999.999-99');
  149.            $this->inscricao->setEditable(FALSE);
  150.     }
  151.     
  152. }
  153.     
  154. }
  155. ?>


quando chamo a função validaCliente, nada acontece
alguem tem uma ideia de cmo fazer?

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (3)


ES

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
FC

  1. <?php
  2. function show()
  3.     {
  4.         $this->validaCliente();
  5.         parent::show();
  6.     }
  7. ?>


como havia te dito acredito que tenha que reinderizar a page de novo acho que é assim não testei....
FC

Alexandre da uma olhada nesse tópico.

https://groups.google.com/forum/#!topic/adianti-tools-pt/aAMNHXvI77E