Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Problemas com setChangeAction Estou com um problema na execução do setChangeAction no TCombo. Quanto executo esta me retornando Fatal error: Using $this when not in object context in C:xampphtdocscompraslibadiantiwidgetbaseTElement.php on line 180. Estou tentando utilizar uma rotina que foi apresentada no próprio forum para esses casos. ...
CA
Problemas com setChangeAction  
Estou com um problema na execução do setChangeAction no TCombo. Quanto executo esta me retornando Fatal error: Using $this when not in object context in C:xampphtdocscompraslibadiantiwidgetbaseTElement.php on line 180. Estou tentando utilizar uma rotina que foi apresentada no próprio forum para esses casos.

  1. <?php
  2. class CadastrarFornecedor extends TPage
  3. {
  4.     protected $form// form
  5.          
  6.     function __construct($param)
  7.     {
  8.         parent::__construct();
  9.     
  10.         // creates the form
  11.         $this->form = new TForm('form_cadastrar_fornecedor');
  12.         $this->form->class 'tform';
  13.         $this->form->style 'max-width: 700px; margin:auto; margin-top:40px;';
  14.         // add the notebook inside the form
  15.         $table = new TTable;
  16.         $table->width '100%';
  17.         $this->form->add($table);
  18.         // create the form fields
  19.         $tipo                = new TCombo('tipo');
  20.         $nome                = new TEntry('nome');
  21.         $fantasia            = new TEntry('fantasia');
  22.         $cpf                 = new TEntry('cpf_cnpj');
  23.         
  24.         $tipo->setChangeAction(new TAction(array($this'onAtualizarCampos')));
  25.         
  26.         $nome->setMaxLength('120');
  27.         $fantasia->setMaxLength('100');
  28.         $cpf->setMaxLength('14');
  29.         
  30.         // add the combo tipo
  31.         $itemstipo = array();
  32.         $itemstipo['1'] = 'PESSOA FÍSICA';
  33.         $itemstipo['2'] = 'PESSOA JURÍDICA';
  34.         $tipo->addItems($itemstipo);
  35.         $row=$table->addRow();
  36.         $row->addCell( new TLabel('Cadastro de Fornecedores') )->colspan 2;
  37.         $row->class='tformtitle';
  38.         $cpf->placeholder 'Apenas números';
  39.         // create the field labels
  40.         $lab_tipo            = new TLabel('Tipo:');
  41.         $lab_nome            = new TLabel('Nome:');
  42.         $lab_fantasia        = new TLabel('Fantasia:');
  43.         $lab_cpf             = new TLabel('CPF:');
  44.         $row=$table->addRow();
  45.         $row->addCell$lab_tipo )->style 'width:20%';
  46.         $row->addCell$tipo );
  47.         $row=$table->addRow();
  48.         $row->addCell$lab_nome );
  49.         $row->addCell$nome );
  50.         $row=$table->addRow();
  51.         $row->addCell$lab_fantasia );
  52.         $row->addCell$fantasia );
  53.         $row=$table->addRow();
  54.         $row->addCell$lab_cpf );
  55.         $row->addCell$cpf );
  56.         // create an action button (save)
  57.         $save_button=new TButton('save');
  58.         // define the button action
  59.         $save_button->setAction(new TAction(array($this'onSave')), 'Gravar Fornecedor');
  60.         $save_button->class 'btn btn-success';
  61.         $save_button->style 'font-size:18px;width:90%;padding:10px';
  62.         $row=$table->addRow();
  63.         $row->class 'tformaction';
  64.         $cell $row->addCell$save_button );
  65.         $cell->colspan 2;
  66.         $cell->style 'text-align:center';
  67.         // create an action button (new)
  68.         $new_button=new TButton('new');
  69.         // define the button action
  70.         $new_button->setAction(new TAction(array('LoginForm''onLogout')), 'Retornar');
  71.         $new_button->class 'btn btn-primary';
  72.         $new_button->style 'font-size:18px;width:90%;padding:10px';
  73.         $row=$table->addRow();
  74.         $row->class 'tformaction';
  75.         $cell $row->addCell$new_button );
  76.         $cell->colspan 2;
  77.         $cell->style 'text-align:center';
  78.         $this->form->setFields(array($tipo$nome$fantasia$cpf$save_button$new_button));
  79.         // add the form to the page
  80.         parent::add($this->form);
  81.     }
  82.     /**
  83.      * Authenticate the User
  84.      */
  85.     public function onSave()
  86.     {
  87.         try
  88.         {
  89.         }
  90.         catch (Exception $e)
  91.         {
  92.         }
  93.     }
  94.     public static function onAtualizarCampos()
  95.     {
  96.         $script = new TElement('script'); 
  97.         $script->type 'text/javascript'
  98.         $javascript " // personaliza os campos de acordo com o tipo de pessoa 
  99.         $('select[name=\"tipo\"]').change(function(event)
  100.         { 
  101.             var tipoPessoa 
  102.             $('select[name=\"tipo\"] > option:selected').each(function(){tipoPessoa = $(this).text();});
  103.             if(tipoPessoa.toLowerCase() == 'pessoa física') 
  104.             { 
  105.                 $('label:contains(CNPJ:)').parent().css('left',82);
  106.                 $('label:contains(CNPJ:)').text('CPF:'); 
  107.                 $('input[name=\"cpf_cnpj\"]').val(''); 
  108.                 $('input[name=\"cpf_cnpj\"]').attr({onkeypress:'return entryMask(this,event,\"999.999.999-99\")'}); 
  109.                 $('input[name=\"fantasia\"]').attr({class:'tfield',readonly:false,value:''});  
  110.             } 
  111.             if(tipoPessoa.toLowerCase() == 'pessoa jurídica') 
  112.             { 
  113.                 $('label:contains(CPF:)').parent().css('left',75);
  114.                 $('label:contains(CPF:)').text('CNPJ:'); 
  115.                 $('input[name=\"cpf_cnpj\"]').val(''); 
  116.                 $('input[name=\"cpf_cnpj\"]').attr({onkeypress:'return entryMask(this,event,\"99.999.999/9999-99\")'});
  117.                 $('input[name=\"fantasia\"]').attr({class:'tfield_disabled',readonly:'1',value:''}); 
  118.             } 
  119.         }); "
  120.         $script->add($javascript); 
  121.         parent::add($script);
  122.  
  123.     }
  124.             
  125. }</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


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (2)


IF

O erro está ocorrendo em parent::add numa function static.

A saída seria vc usar o TScript::create()
MG

Você pode usar a dica do Ivan ou adicionar o elemento diretamente no construtor usando 'on' sem necessidade de utilizar um "TAction":
;;;;; $(document).on('change','select[name=\"tipo\"]' , function(event){ .....>/code>