LH
            
                Preenchimento automático de campos da mesma tabela  
                
                
            
            
            
            Bom dia, estou tentando puxar informações da mesma tabela como preenchimento automático. Faz 3 dias que estou nesse problema e tem algo que esta faltando. 
Preciso que, ao digitar o CPF do usuário, o campo Cliente seja preenchido automático.
Tabela: ativos (system_user_name = name cliente) (system_user_id = cpf)
            
            
        Preciso que, ao digitar o CPF do usuário, o campo Cliente seja preenchido automático.
Tabela: ativos (system_user_name = name cliente) (system_user_id = cpf)
 - <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_erros', 1);
- error_reporting(E_ALL);
- class AtivaPromocao extends TPage
- {
-     private $form;
-     public function __construct()
-     {
-         parent::__construct();
-         //parent::setFormTitle( "Cadastro de Profissionais" );
-         //parent::setSize( 0.600, 0.800 );
-         $redstar = '<font color="red"><b>*</b></font>';
-         $this->form = new BootstrapFormBuilder( "form_ativa" );
-         $this->form->setFormTitle( "Ativar Voucher" );
-         $this->form->class = "tform";
-         $id                 = new THidden( "id" );
-         $empresa_id         = new TDBUniqueSearch( 'empresa_id', 'database', 'EmpresaRecord', 'id', 'nomefantasia', 'nomefantasia' );
-         $voucher_id         = new TDBCombo( 'voucher_id', 'database', 'VoucherRecord', 'id', 'nomeproduto', 'nomeproduto');
-         $state_id           = new TDBCombo('system_user_id', 'database', 'SystemUser', 'id', 'cpf', 'cpf');
-         $state_id           ->enableSearch();
-         $filter             = new TCriteria();
-         $filter             ->add(new TFilter('id', '<', '0'));
-         $city_id            = new TDBCombo('system_user_name', 'database', 'SystemUser', 'id', 'name', 'name', $filter);
-         $city_id            ->enableSearch();
-         //$change_action = new TAction(array($this, 'onChange'));
-         //$system_user_id->setChangeAction($change_action);
-         //$system_user_name->setEditable(FALSE);
-         $state_id->setSize('50%');
-         $this->form->addFields( [ $id ] );
-         $this->form->addFields( [new TLabel("CPF: {$redstar}")], [$state_id] );
-         $this->form->addFields( [new TLabel("Cliente: {$redstar}")], [$city_id] );
-         $this->form->addFields([]);
-         $this->form->addFields( [new TLabel("Empresa: {$redstar}")], [$empresa_id] );
-         $this->form->addFields( [new TLabel("Produto: {$redstar}")], [$voucher_id] );
-         $state_id->setChangeAction( new TAction( array($this, 'onStateChange' )) );
-         $this->form->addAction( 'Salvar', new TAction( [ $this, "onSave" ] ), 'fa:floppy-o' )->class = 'btn btn-sm btn-success';
-         $this->form->addAction('Voltar', new TAction(array('VoucherList', 'onReload')), 'fa:arrow-left')->class = 'btn btn-sm btn-primary';
-         $container = new TVBox();
-         $container->style = "width: 100%";
-         $container->add( $this->form );
-         parent::add( $container );
-     }
-     public function onSave($param)
-     {
-         try
-         {
-             TTransaction::open('database');
-             $this->form->validate();
-             $object = new Test;
-             $data = $this->form->getData();
-             $object->fromArray((array) $data);
-             $object->store();
-             $data->id = $object->id;
-             $this->form->setData($data);
-             $this->fireEvents($object);
-             TTransaction::close();
-             new TMessage('info', TAdiantiCoreTranslator::translate('AtivaRecord'));
-         } catch (Exception $e)
-         {
-             new TMessage('error', $e->getMessage());
-             $this->form->setData($this->form->getData());
-             TTransaction::rolback();
-         }
-     }
-     public function fireEvents($param)
-     {
-         $obj = new StdClass;
-         $obj->state_id = $object->state_id;
-         $obj->city_id = $object->city_id;
-         TForm::sendData('form_ativa', $obj);
-     }
-     public static function onStateChange($param)
-     {
-         try
-         {
-             TTransaction::open('database');
-             if (!empty($param['system_user_id']))
-             {
-                 $criteria = TCriteria::create( ['name' => $param['system_user_id'] ] );
-                 
-                 TDBCombo::reloadFromModel('form_ativa', 'system_user_name', 'database', 'SystemUSer', 'id', 'name', 'name', $criteria, TRUE);
-             }
-             else
-             {
-                 TCombo::clearField('form_ativa', 'system_user_name');
-             }
-             
-             TTransaction::close();
-         }
-         catch (Exception $e)
-         {
-             new TMessage('error', $e->getMessage());
-         }
-         //var_dump($param);
-     }
-     /*public static function onChange($param)
-     {
-         TTransaction::open("database");
-         $criteria = new TCriteria();
-         $criteria->add(new TFilter('cpf', '=', $param['system_user_id']));
-         $repository = new TRepository("SystemUser");
-         $users = $repository->load($criteria);
-         $options = array();
-         foreach($users as $user){
-             $options[$user->id] = $user->name;
-         }
-             
-         //var_dump($param);
-         TCombo::reload('form_ativa', 'system_user_name', $options);
-         
-     }
-     public function onSave()
-     {
-         try {
-             $this->form->validate();
-             TTransaction::open( "database" );
-             $object = $this->form->getData("AtivaRecord");
-             $object->store();
-             TTransaction::close();
-             $action = new TAction( [ "VoucherList", "onReload" ] );
-             new TMessage( "info", "Registro salvo com sucesso!", $action );
-         } catch ( Exception $ex ) {
-             TTransaction::rollback();
-             new TMessage( "error", "Ocorreu um erro ao tentar salvar o registro!<br><br><br><br>" . $ex->getMessage() );
-         }
-     }*/
-     public function onEdit( $param )
-     {
-         try {
-             if( isset( $param[ "key" ] ) ) {
-                 TTransaction::open( "database" );
-                 $object = new AtivaRecord($param["key"]);
-                 $this->form->setData($object);
-                 TTransaction::close();
-             }
-         } catch ( Exception $ex ) {
-             TTransaction::rollback();
-             new TMessage( "error", "Ocorreu um erro ao tentar carregar o registro para edição!<br><br>" . $ex->getMessage() );
-         }
-     }
- }
Luis,
Crei essa action
e depois
Luis,
Crei essa action e depois
Ele da esse erro!
Exceção
Método setExitAction() não encontrado
File: appcontrolcadastrosAtivaPromocao.class.php : 23
AdiantiWidgetFormTField->__call(setExitAction,AdiantiControlTAction)
File: libadianticoreAdiantiCoreApplication.php : 62
AtivaPromocao->__construct(AtivaPromocao)
File: engine.php : 23
AdiantiCoreAdiantiCoreApplication::run(1)
File: engine.php : 64
TApplication::run(1)
Troca combo por tentry
Para Dbcombo o metodo eh outro
setChangeAction
E não setExitaction
Quando eu dou um var_dump no $param ele não puxa o city_id.
Resolvi, era só o filtro errado. Devia está puxando o ID. kkkk Vlwww