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:
segue como fica a tela e o codigo:
- <?php
- /**
- * cadastro_unidade Form
- * @author <your name here>
- */
- class cadastro_unidade extends TPage
- {
- //protected $form; // form
- private $form; // form
- private $contacts;
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_unidade');
- $this->form->setFormTitle('unidade');
- $this->form->setFieldSizes('100%');
- // Campos da Aba Endereco
- $this->form->appendPage('Endereço');
- // create the form fields
- $id = new TEntry('id');
- $siglaunidade = new TEntry('siglaunidade');
- $rzsocial = new TEntry('rzsocial');
- $nomefantasia = new TEntry('nomefantasia');
- $email = new TEntry('email');
- $telefone = new TEntry('telefone');
- $telefoneadm = new TEntry('telefoneadm');
- $cep = new TEntry('cep');
- $endereco = new TEntry('endereco');
- $numero = new TEntry('numero');
- $complemento = new TEntry('complemento');
- $uf = new TEntry('uf');
- $cidade = new TEntry('cidade');
- $bairro = new TEntry('bairro');
- $cnae = new TEntry('cnae');
- // add the fields
- $row = $this->form->addFields( [ new TLabel('Código'), $id ],
- [ new TLabel('Sigla da Unidade'), $siglaunidade ],
- [ new TLabel('Razão Social'), $rzsocial ] );
- $row->layout = ['col-sm-2', 'col-sm-4', 'col-sm-6' ];
- $row = $this->form->addFields( [ new TLabel('Nome Fantasia'), $nomefantasia ],
- [ new TLabel('Email'), $email ] );
- $row->layout = ['col-sm-6', 'col-sm-6' ];
- $row = $this->form->addFields( [ new TLabel('Telefone 1'), $telefone ],
- [ new TLabel('Telefone 2'), $telefoneadm ] );
- $row->layout = ['col-sm-6', 'col-sm-6' ];
- $row = $this->form->addFields( [ new TLabel('CEP'), $cep ],
- [ new TLabel('Endereço'), $endereco ],
- [ new TLabel('Número'), $numero ] );
- $row->layout = ['col-sm-3', 'col-sm-6', 'col-sm-3' ];
- $row = $this->form->addFields( [ new TLabel('Complemento'), $complemento ],
- [ new TLabel('U.F'), $uf ] );
- $row->layout = ['col-sm-9', 'col-sm-3' ];
- $row = $this->form->addFields( [ new TLabel('Cidade'), $cidade ],
- [ new TLabel('Bairro'), $bairro ],
- [ new TLabel('CNAE'), $cnae ] );
- $row->layout = ['col-sm-3', 'col-sm-6', 'col-sm-3' ];
- // Campos da aba Documentos
- $this->form->appendPage('Documentos');
- // create the form fields
- $cnpj = new TEntry('cnpj');
- $ie = new TEntry('ie');
- $im = new TEntry('im');
- $portedaempresa = new TEntry('portedaempresa');
- $emitedocfiscal = new TCombo('emitedocfiscal');
- $optasn = new TCombo('optasn');
- //Campo Simples Nacional
- $itemoptasn = array();
- $itemoptasn ['Sim']='Sim';
- $itemoptasn ['Não']='Não';
- $optasn->addItems($itemoptasn);
- //Campo emite documento fiscal
- $itememitedocfiscal = array();
- $itememitedocfiscal ['Sim']='Sim';
- $itememitedocfiscal ['Não']='Não';
- $emitedocfiscal->addItems($itememitedocfiscal);
- // Exibe os campos da aba documentos
- $row = $this->form->addFields( [ new TLabel('CNPJ'), $cnpj ],
- [ new TLabel('I.E'), $ie ],
- [ new TLabel('I.M'), $im ] );
- $row->layout = ['col-sm-4', 'col-sm-4', 'col-sm-4' ];
- $row = $this->form->addFields( [ new TLabel('Porte da Empresa'), $portedaempresa ],
- [ new TLabel('Emite documento fiscal?'),$emitedocfiscal ],
- [ new TLabel('Optante do Simples?'), $optasn ] );
- $row->layout = ['col-sm-4', 'col-sm-4', 'col-sm-4' ];
- //$this->form->appendPage('Skills');
- //$skill_list = new TDBCheckGroup('skill_list', 'samples', 'Skill', 'id', 'name');
- //$this->form->addFields( [ new TLabel('Skill') ], [ $skill_list ] );
- //validação de campos
- $siglaunidade->addValidation('Sigla da unidade', new TRequiredValidator);
- $siglaunidade->addValidation('Sigla da unidade', new TMaxLengthValidator,array(10));
- $rzsocial ->addValidation('Razão Social', new TRequiredValidator);
- $nomefantasia->addValidation('Nome Fantasia', new TRequiredValidator);
- $cnpj ->addValidation('CNPJ', new TCNPJValidator);
- $email ->addValidation('E-mail', new TEmailValidator);
- $cep ->addValidation('C.E.P', new TRequiredValidator);
- $endereco ->addValidation('Endereço', new TRequiredValidator);
- $numero ->addValidation('Número', new TRequiredValidator);
- $numero ->addValidation('Número', new TMaxLengthValidator,array(10));
- $uf ->addValidation('U.F', new TRequiredValidator);
- $uf ->addValidation('U.F', new TMaxLengthValidator,array(2));
- $cidade ->addValidation('Cidade', new TRequiredValidator);
- $bairro ->addValidation('Bairro', new TRequiredValidator);
- $portedaempresa->addValidation('Porte da empresa', new TRequiredValidator);
- $portedaempresa->addValidation('Porte da empresa', new TMaxLengthValidator,array(10));
- $emitedocfiscal->addValidation('Emite documento fiscal', new TRequiredValidator);
- $optasn ->addValidation('Optante do Simples Nacional', new TRequiredValidator);
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
- /** samples
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( '100%' ); // set size
- **/
- $this->form->appendPage('Contacts');
- $contact_type = new TEntry('contact_type[]');
- $contact_type->setSize('100%');
- $contact_value = new TEntry('contact_value[]');
- $contact_value->setSize('100%');
- $this->contacts = new TFieldList;
- $this->contacts->addField( '<b>Type</b>', $contact_type, ['width' => '50%']);
- $this->contacts->addField( '<b>Value</b>', $contact_value, ['width' => '50%']);
- $this->form->addField($contact_type);
- $this->form->addField($contact_value);
- $this->contacts->enableSorting();
- $this->form->addContent( [ new TLabel('Contacts') ], [ $this->contacts ] );
- // create the form actions
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('banco'); // open a transaction
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
- $this->form->validate(); // validate form data
- $data = $this->form->getData(); // get form data as array
- $object = new unidade; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- // get the generated id
- $data->id = $object->id;
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear(TRUE);
- }
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('banco'); // open a transaction
- $object = new unidade($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
Wempar Ferreira,
Adicione este código no método onClear
$this->contacts->addHeader();
$this->contacts->addDetail( new stdClass );
$this->contacts->addCloneAction();
Entendi o que esta faltando, obrigado.