Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Problemas ao usar Form com Notebook Oi. Estou tendo problemas em acessar os dados de um formulário dentro de notebook e a manipulação de botões: Mais precisamente, pq essa linha de código não funciona?? TButton::disableField('form_Teste', 'save'); ...
GE
Problemas ao usar Form com Notebook  
Fechado
Oi.
Estou tendo problemas em acessar os dados de um formulário dentro de notebook e a manipulação de botões:

Mais precisamente, pq essa linha de código não funciona??
TButton::disableField('form_Teste', 'save');

  1. <?php
  2. class CommonPage extends TPage
  3. {
  4.     
  5.     protected $form// form
  6.         
  7.         
  8.     public function __construct()
  9.     {
  10.        parent::__construct();
  11.         
  12.         $this->form = new TForm('form_Teste');
  13.     
  14.         // creates the notebook
  15.         $notebook = new TNotebook(400,250);
  16.         
  17.         // creates the containers for each notebook page
  18.         $page1 = new TTable;
  19.         $page2 = new TPanel(370,180);
  20.         $page3 = new TTable;
  21.         
  22.         $this->form->add($notebook);
  23.         
  24.         // adds two pages in the notebook
  25.         $notebook->appendPage('Basic data'$page1);
  26.         $notebook->appendPage('Other data'$page2);
  27.         $notebook->appendPage('Other note'$page3);
  28.         
  29.         // create the form fields
  30.         $field1 = new TEntry('field1');
  31.         $field2 = new TEntry('field2');
  32.         $field3 = new TEntry('field3');
  33.         $field4 = new TEntry('field4');
  34.         $field5 = new TEntry('field5');
  35.         
  36.         $field6 = new TEntry('field6');
  37.         $field7 = new TEntry('field7');
  38.         $field8 = new TEntry('field8');
  39.         $field9 = new TEntry('field9');
  40.         $field10= new TEntry('field10');
  41.         
  42.         // change the size for some fields
  43.         $field1->setSize(100);
  44.         $field2->setSize(80);
  45.         $field3->setSize(150);
  46.         
  47.         $field6->setSize(80);
  48.         $field7->setSize(80);
  49.         $field8->setSize(80);
  50.         $field9->setSize(80);
  51.         $field10->setSize(80);
  52.         
  53.         ## fields for the page 1 ##
  54.         
  55.         // add a row for a label
  56.         $row=$page1->addRow();
  57.         $cell=$row->addCell(new TLabel('<b>Table Layout</b>'));
  58.         $cell->valign 'top';
  59.         $cell->colspan=2;
  60.         
  61.         // adds a row for a field
  62.         $row=$page1->addRow();
  63.         $row->addCell(new TLabel('Field1:'));
  64.         $row->addCell($field1);
  65.         
  66.         // adds a row for a field
  67.         $row=$page1->addRow();
  68.         $row->addCell(new TLabel('Field2:'));
  69.         $cell $row->addCell($field2);
  70.         $cell->colspan=3;
  71.         
  72.         // adds a row for a field
  73.         $row=$page1->addRow();
  74.         $row->addCell(new TLabel('Field3:'));
  75.         $cell $row->addCell($field3);
  76.         $cell->colspan=3;
  77.         
  78.         // adds a row for a field
  79.         $row=$page1->addRow();
  80.         $row->addCell(new TLabel('Field4:'));
  81.         $row->addCell($field4);
  82.         
  83.         // adds a row for a field
  84.         $row=$page1->addRow();
  85.         $row->addCell(new TLabel('Field5:'));
  86.         $row->addCell($field5);
  87.         
  88.         
  89.         ## fields for the page 2 ##
  90.         
  91.         $page2->put(new TLabel('<b>Panel Layout</b>'), 44);
  92.         $page2->put(new TLabel('Field6'),  20,  30);
  93.         $page2->put(new TLabel('Field7'),  50,  60);
  94.         $page2->put(new TLabel('Field8'),  80,  90);
  95.         $page2->put(new TLabel('Field9'), 110120);
  96.         $page2->put(new TLabel('Field10'),140150);
  97.         
  98.         $page2->put($field6120,  30);
  99.         $page2->put($field7150,  60);
  100.         $page2->put($field8180,  90);
  101.         $page2->put($field9210120);
  102.         $page2->put($field10,240150);
  103.         
  104.         
  105.         ## fields for the page 3 ##
  106.         
  107.         // creates the notebook
  108.         $subnotebook = new TNotebook(250160);
  109.         $subnotebook->appendPage('new page1', new TLabel('test1'));
  110.         $subnotebook->appendPage('new page2', new TText('test2'));
  111.         
  112.         $row $page3->addRow();
  113.         $row->addCell($subnotebook);
  114.         
  115.                 // create the form actions
  116.         $save_button   TButton::create('save', array($this'onSave'), _t('Save'), 'ico_save.png');
  117.         $delete_button TButton::create('delete', array($this'onDelete'), _t('Delete'), 'ico_delete.png');
  118.         $new_button    TButton::create('new',  array($this'onEdit'), _t('New'),  'ico_new.png');
  119. //        $list_button   = TButton::create('list', array('FilmeList', 'onReload'), _t('List'), 'ico_datagrid.png');
  120.         
  121.         $this->form->addField($save_button);
  122.         $this->form->addField($delete_button);
  123.         $this->form->addField($new_button);
  124. //        $this->form->addField($list_button);
  125.         
  126.         $subtable = new TTable;
  127.         $row $subtable->addRow();
  128.         $row->addCell($save_button);
  129.         $row->addCell($delete_button);
  130.         $row->addCell($new_button);
  131. //        $row->addCell($list_button);
  132.          
  133.         $vbox = new TVBox;
  134.         $vbox->add($notebook);
  135.         $vbox->add($subtable);    
  136.   
  137.   TButton::disableField('form_Teste''save');
  138.             
  139.         parent::add($vbox);
  140.         
  141.     }
  142.     
  143.         /**
  144.      * method onSave()
  145.      * Executed whenever the user clicks at the save button
  146.      */
  147.     function onSave()
  148.     {
  149.         try
  150.         {
  151.             TTransaction::open('filme'); // open a transaction
  152.             
  153.             // get the form data into an active record Filme
  154.             $object $this->form->getData('Filme');          
  155.             
  156.             $object->dataVisualizacao $this->formatDate($object->dataVisualizacao);
  157.             
  158.             if($object->genero_list)
  159.             {
  160.                 foreach($object->genero_list as $genero_id)
  161.                 {
  162.                     $object->addGenero(new Genero($genero_id));
  163.                 }
  164.             }
  165.         
  166.             $this->form->validate(); // form validation
  167.             $object->store(); // stores the object
  168.             $object->dataVisualizacao $this->formatDateBR($object->dataVisualizacao);
  169.             $this->form->setData($object); // keep form data
  170.             
  171.            // $this->upload($object->imagem, 'teste');
  172.             TTransaction::close(); // close the transaction
  173.             
  174.             // shows the success message
  175.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  176.         }
  177.         catch (Exception $e// in case of exception
  178.         {
  179.             new TMessage('error''<b>Erros encontrados:</b> <br />' $e->getMessage()); // shows the exception error message
  180.             $this->form->setData$this->form->getData() ); // keep form data
  181.             TTransaction::rollback(); // undo all pending operations
  182.         }
  183.         
  184.         if ($object instanceof Filme)
  185.         {
  186.             $source_file   'tmp/'.$object->photo_path;
  187.             $target_file   'app/images/foto/' $object->id.'.png';
  188.           
  189.             $finfo = new finfo(FILEINFO_MIME_TYPE);
  190.             
  191.             if (file_exists($source_file) AND ($finfo->file($source_file) == 'image/png' OR $finfo->file($source_file) == 'image/jpeg'))
  192.             {
  193.                 // move to the target directory
  194.                 rename($source_file$target_file);
  195.                
  196.             } 
  197.             else
  198.             {
  199.                  if($object->photo_path)
  200.                  {
  201.                      new TMessage('error''<b>Arquivo de imagem inálido</b> <br />'); // shows the exception error message
  202.                  }                 
  203.             }                    
  204.         }
  205.         
  206.     }
  207.     
  208.         /**
  209.      * method onEdit()
  210.      * Executed whenever the user clicks at the edit button da datagrid
  211.      */
  212.     function onEdit($param)
  213.     {
  214.         try
  215.         {
  216.             if (isset($param['key']))
  217.             {
  218.                 $key=$param['key'];  // get the parameter $key
  219.                 TTransaction::open('filme'); // open a transaction
  220.                 $object = new Filme($key); // instantiates the Active Record
  221.                 
  222.                 if(!$object->dataVisualizacao)
  223.                 {
  224.                     $object->dataVisualizacao $object->datavisualizacao;
  225.                 }
  226.                 
  227.                 $object->dataVisualizacao $this->formatDateBR($object->dataVisualizacao);
  228.                 
  229.                 $generos $object->getGeneros();
  230.                 $genero_list = array();
  231.                 if($generos)
  232.                 {
  233.                     foreach ($generos as $genero)
  234.                     {
  235.                         $genero_list[] = $genero->id;
  236.                     }
  237.                 }
  238.                 $object->genero_list $genero_list;
  239.                 
  240.                 $this->form->setData($object); // fill the form
  241.                 TTransaction::close(); // close the transaction
  242.             }
  243.             else
  244.             {
  245.                 $object = new StdClass;
  246.                 $object->nota 1;
  247.                 
  248.                 $this->form->clear();
  249.                 $this->form->setData($object); // fill the form
  250.             }
  251.         }
  252.         catch (Exception $e// in case of exception
  253.         {
  254.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  255.             TTransaction::rollback(); // undo all pending operations
  256.         }
  257.     }
  258.     
  259.        /**
  260.      * method onDelete()
  261.      * executed whenever the user clicks at the delete button
  262.      * Ask if the user really wants to delete the record
  263.      */
  264.     function onDelete($param)
  265.     {
  266.         // define the delete action
  267.         $action = new TAction(array($this'Delete'));
  268.         $action->setParameters($param); // pass the key parameter ahead
  269.         
  270.         // shows a dialog to the user
  271.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  272.     }
  273.     
  274.      /**
  275.      * method Delete()
  276.      * Delete a record
  277.      */
  278.     function Delete($param)
  279.     {
  280.         try
  281.         {
  282.             $key=$param['id']; // get the parameter $key
  283.             TTransaction::open('filme'); // open a transaction with database
  284.             $object = new Filme($keyFALSE); // instantiates the Active Record
  285.             $object->delete(); // deletes the object from the database
  286.             TTransaction::close(); // close the transaction
  287.             $object = new StdClass;
  288.             $object->nota 1;
  289.             $this->form->clear();
  290.             $this->form->setData($object); // fill the form
  291.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted')); // success message
  292.         }
  293.         catch (Exception $e// in case of exception
  294.         {
  295.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  296.             TTransaction::rollback(); // undo all pending operations
  297.         }
  298.     }
  299.     
  300.     public function formatDate($date)
  301.     {        
  302.         $dt explode('/'$date);
  303.         $retorno $dt[2].'-'.$dt[1].'-'.$dt[0];
  304.         return $retorno;
  305.     }
  306.     public function formatDateBR($date)
  307.     {        
  308.         $dt explode('-'$date);
  309.         $retorno $dt[2].'/'.$dt[1].'/'.$dt[0];
  310.         return $retorno;
  311.     }    
  312.     
  313. }
  314. ?>



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 (3)


FC

Ue esse recurso para desabilitar deveria estar dentro de uma função estática não solta na parte de criação da page vc deveria montar a page já com o botão desabilitado com o setEnabled = False

Depois se houver necessidade ativar o mesmo num evento posterior.
GE

Oi Felipe.
Quando utilizo o onExitAction eu utilizo classe estática.

Mas nesse caso não funciona. Acredito que deva ser algo no meu empacotamento de form, table e notebook.
Tenho outras páginas que desabilito o botão no constructor e conforme as ações do formulario eu habilito ele.
GE

Realmente o problema era o empacotamento, sendo que no código os botões estavam fora do form.

$vbox = new TVBox; $vbox->add($notebook); $vbox->add($subtable); $this->form->add($vbox); TButton::disableField('form_Teste', 'save'); parent::add($this->form);