Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Cadastro de clientes - não consigo criar aba contatos Boa noite, estou estudando o sistema e agora estou fazendo uma tela de cadastro de clientes, porém não consigo colocar a aba contatos, estou me baseando no exemplos do tutor. segue como fica a tela e o codigo: ...
WF
Cadastro de clientes - não consigo criar aba contatos  
Boa noite, estou estudando o sistema e agora estou fazendo uma tela de cadastro de clientes, porém não consigo colocar a aba contatos, estou me baseando no exemplos do tutor.

segue como fica a tela e o codigo:

  1. <?php
  2. /**
  3.  * cadastro_unidade Form
  4.  * @author  <your name here>
  5.  */
  6. class cadastro_unidade extends TPage
  7. {
  8.     //protected $form; // form
  9.      private $form// form
  10.     private $contacts;
  11.     /**
  12.      * Form constructor
  13.      * @param $param Request
  14.      */
  15.     public function __construct$param )
  16.     {
  17.         parent::__construct();
  18.         
  19.         // creates the form
  20.         $this->form = new BootstrapFormBuilder('form_unidade');
  21.         $this->form->setFormTitle('unidade');
  22.         $this->form->setFieldSizes('100%');
  23.         
  24.         // Campos da Aba Endereco
  25.         $this->form->appendPage('Endereço');
  26.         // create the form fields
  27.         $id = new TEntry('id');
  28.         $siglaunidade = new TEntry('siglaunidade');
  29.         $rzsocial = new TEntry('rzsocial');
  30.         $nomefantasia = new TEntry('nomefantasia');
  31.         $email = new TEntry('email');
  32.         $telefone = new TEntry('telefone');
  33.         $telefoneadm = new TEntry('telefoneadm');
  34.         $cep = new TEntry('cep');
  35.         $endereco = new TEntry('endereco');
  36.         $numero = new TEntry('numero');
  37.         $complemento = new TEntry('complemento');
  38.         $uf = new TEntry('uf');
  39.         $cidade = new TEntry('cidade');
  40.         $bairro = new TEntry('bairro');
  41.         $cnae = new TEntry('cnae');
  42.         // add the fields
  43.         $row $this->form->addFields( [ new TLabel('Código'),                 $id ],
  44.                                        [ new TLabel('Sigla da Unidade'),       $siglaunidade ],
  45.                                        [ new TLabel('Razão Social'),           $rzsocial ] );
  46.         $row->layout = ['col-sm-2''col-sm-4''col-sm-6' ];
  47.         
  48.         $row $this->form->addFields( [ new TLabel('Nome Fantasia'),      $nomefantasia ],            
  49.                                        [ new TLabel('Email'),              $email ] );
  50.         $row->layout = ['col-sm-6''col-sm-6' ];
  51.         
  52.         $row $this->form->addFields( [ new TLabel('Telefone 1'),       $telefone ],            
  53.                                        [ new TLabel('Telefone 2'),       $telefoneadm ] );
  54.         $row->layout = ['col-sm-6''col-sm-6' ];
  55.         
  56.         $row $this->form->addFields( [ new TLabel('CEP'),            $cep ],
  57.                                        [ new TLabel('Endereço'),       $endereco ],
  58.                                        [ new TLabel('Número'),         $numero ] );
  59.         $row->layout = ['col-sm-3''col-sm-6''col-sm-3' ];
  60.         
  61.         $row $this->form->addFields( [ new TLabel('Complemento'),      $complemento ],            
  62.                                        [ new TLabel('U.F'),              $uf ] );
  63.         $row->layout = ['col-sm-9''col-sm-3' ];
  64.         
  65.         $row $this->form->addFields( [ new TLabel('Cidade'),       $cidade ],
  66.                                        [ new TLabel('Bairro'),       $bairro ],
  67.                                        [ new TLabel('CNAE'),         $cnae ] );
  68.         $row->layout = ['col-sm-3''col-sm-6''col-sm-3' ];
  69.           
  70.         // Campos da aba Documentos 
  71.         $this->form->appendPage('Documentos');
  72.         // create the form fields
  73.         $cnpj = new TEntry('cnpj');
  74.         $ie = new TEntry('ie');
  75.         $im = new TEntry('im');
  76.         $portedaempresa = new TEntry('portedaempresa');
  77.         $emitedocfiscal = new TCombo('emitedocfiscal');
  78.         $optasn = new TCombo('optasn');
  79.         
  80.         //Campo Simples Nacional
  81.         $itemoptasn = array();
  82.         $itemoptasn ['Sim']='Sim';  
  83.         $itemoptasn ['Não']='Não';    
  84.         $optasn->addItems($itemoptasn); 
  85.         
  86.         //Campo emite documento fiscal
  87.         $itememitedocfiscal = array();
  88.         $itememitedocfiscal ['Sim']='Sim';  
  89.         $itememitedocfiscal ['Não']='Não';    
  90.         $emitedocfiscal->addItems($itememitedocfiscal); 
  91.         
  92.         
  93.         
  94.         // Exibe os campos da aba documentos
  95.         $row $this->form->addFields( [ new TLabel('CNPJ'),      $cnpj ],
  96.                                        [ new TLabel('I.E'),       $ie ],
  97.                                        [ new TLabel('I.M'), $im ] );
  98.         $row->layout = ['col-sm-4''col-sm-4''col-sm-4' ];
  99.         
  100.         $row $this->form->addFields( [ new TLabel('Porte da Empresa'),       $portedaempresa ],
  101.                                        [ new TLabel('Emite documento fiscal?'),$emitedocfiscal ],
  102.                                        [ new TLabel('Optante do Simples?'),    $optasn ] );
  103.         $row->layout = ['col-sm-4''col-sm-4''col-sm-4' ];
  104.         
  105.         
  106.         //$this->form->appendPage('Skills');
  107.         //$skill_list = new TDBCheckGroup('skill_list', 'samples', 'Skill', 'id', 'name');
  108.         //$this->form->addFields( [ new TLabel('Skill') ],     [ $skill_list ] );
  109.         
  110.         
  111.         
  112.         //validação de campos
  113.         $siglaunidade->addValidation('Sigla da unidade', new TRequiredValidator);
  114.         $siglaunidade->addValidation('Sigla da unidade', new TMaxLengthValidator,array(10));
  115.         $rzsocial    ->addValidation('Razão Social', new TRequiredValidator);
  116.         $nomefantasia->addValidation('Nome Fantasia', new TRequiredValidator);
  117.         $cnpj        ->addValidation('CNPJ', new TCNPJValidator); 
  118.         $email       ->addValidation('E-mail', new TEmailValidator); 
  119.         $cep         ->addValidation('C.E.P', new TRequiredValidator);
  120.         $endereco    ->addValidation('Endereço', new TRequiredValidator);
  121.         $numero      ->addValidation('Número', new TRequiredValidator);
  122.         $numero      ->addValidation('Número', new TMaxLengthValidator,array(10));
  123.         $uf          ->addValidation('U.F', new TRequiredValidator);
  124.         $uf          ->addValidation('U.F', new TMaxLengthValidator,array(2));
  125.         $cidade      ->addValidation('Cidade', new TRequiredValidator);
  126.         $bairro      ->addValidation('Bairro', new TRequiredValidator);
  127.         $portedaempresa->addValidation('Porte da empresa', new TRequiredValidator);
  128.         $portedaempresa->addValidation('Porte da empresa', new TMaxLengthValidator,array(10));
  129.         $emitedocfiscal->addValidation('Emite documento fiscal', new TRequiredValidator);
  130.         $optasn        ->addValidation('Optante do Simples Nacional', new TRequiredValidator);
  131.         if (!empty($id))
  132.         {
  133.             $id->setEditable(FALSE);
  134.         }
  135.         
  136.         /** samples
  137.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  138.          $fieldX->setSize( '100%' ); // set size
  139.          **/
  140.         
  141.         $this->form->appendPage('Contacts');
  142.         $contact_type = new TEntry('contact_type[]');
  143.         $contact_type->setSize('100%');
  144.         
  145.         $contact_value = new TEntry('contact_value[]');
  146.         $contact_value->setSize('100%');
  147.         
  148.        
  149.         
  150.         $this->contacts = new TFieldList;
  151.         $this->contacts->addField'<b>Type</b>'$contact_type, ['width' => '50%']);
  152.         $this->contacts->addField'<b>Value</b>'$contact_value, ['width' => '50%']);
  153.         $this->form->addField($contact_type);
  154.         $this->form->addField($contact_value);
  155.         $this->contacts->enableSorting();
  156.         
  157.         $this->form->addContent( [ new TLabel('Contacts') ], [ $this->contacts ] );
  158.          
  159.          
  160.         // create the form actions
  161.         $btn $this->form->addAction(_t('Save'), new TAction([$this'onSave']), 'fa:floppy-o');
  162.         $btn->class 'btn btn-sm btn-primary';
  163.         $this->form->addAction(_t('New'),  new TAction([$this'onEdit']), 'fa:eraser red');
  164.         
  165.         // vertical box container
  166.         $container = new TVBox;
  167.         $container->style 'width: 90%';
  168.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  169.         $container->add($this->form);
  170.         
  171.         parent::add($container);
  172.     }
  173.     /**
  174.      * Save form data
  175.      * @param $param Request
  176.      */
  177.     public function onSave$param )
  178.     {
  179.         try
  180.         {
  181.             TTransaction::open('banco'); // open a transaction
  182.             
  183.             /**
  184.             // Enable Debug logger for SQL operations inside the transaction
  185.             TTransaction::setLogger(new TLoggerSTD); // standard output
  186.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  187.             **/
  188.             
  189.             $this->form->validate(); // validate form data
  190.             $data $this->form->getData(); // get form data as array
  191.             
  192.             $object = new unidade;  // create an empty object
  193.             $object->fromArray( (array) $data); // load the object with data
  194.             $object->store(); // save the object
  195.             
  196.             // get the generated id
  197.             $data->id $object->id;
  198.             
  199.             $this->form->setData($data); // fill form data
  200.             TTransaction::close(); // close the transaction
  201.             
  202.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  203.         }
  204.         catch (Exception $e// in case of exception
  205.         {
  206.             new TMessage('error'$e->getMessage()); // shows the exception error message
  207.             $this->form->setData$this->form->getData() ); // keep form data
  208.             TTransaction::rollback(); // undo all pending operations
  209.         }
  210.     }
  211.     
  212.     /**
  213.      * Clear form data
  214.      * @param $param Request
  215.      */
  216.     public function onClear$param )
  217.     {
  218.         $this->form->clear(TRUE);
  219.     }
  220.     
  221.     /**
  222.      * Load object to form data
  223.      * @param $param Request
  224.      */
  225.     public function onEdit$param )
  226.     {
  227.         try
  228.         {
  229.             if (isset($param['key']))
  230.             {
  231.                 $key $param['key'];  // get the parameter $key
  232.                 TTransaction::open('banco'); // open a transaction
  233.                 $object = new unidade($key); // instantiates the Active Record
  234.                 $this->form->setData($object); // fill the form
  235.                 TTransaction::close(); // close the transaction
  236.             }
  237.             else
  238.             {
  239.                 $this->form->clear(TRUE);
  240.             }
  241.         }
  242.         catch (Exception $e// in case of exception
  243.         {
  244.             new TMessage('error'$e->getMessage()); // shows the exception error message
  245.             TTransaction::rollback(); // undo all pending operations
  246.         }
  247.     }
  248. }

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


JS

Wempar Ferreira,

Adicione este código no método onClear

$this->contacts->addHeader();

$this->contacts->addDetail( new stdClass );

$this->contacts->addCloneAction();
WF

Entendi o que esta faltando, obrigado.