Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TMultfield boa noite galera queria saber se existe maneira de mostrar 3 campo no TMultfiel, ou mais de 3 abraços...
AS
TMultfield  
Fechado
boa noite galera queria saber se existe maneira de mostrar 3 campo no TMultfiel, ou mais de 3

abraços

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


MS

Bom dia Alexandre, eu tenho multifields com 8 campos. Eu fiz apenas 8 vezes o TMultifield.addField(). Só precisei alterar a classe TMultifield para conseguir alinhar os campos lado-a-lado e colocar colspan neles.

Abraço.
AS

Mailson da Silva, bom dia
poderia compartilhar o codigo, para mi ter uma ideia de como fazer?
MS

Claro, esse código eu peguei do Tutor e adicionei a 3ª coluna "teste".
  1. <?php
  2.         $contacts_list  = new TMultiField('contacts_list');
  3.         $contacts_list->setHeight(100);
  4.         $contacts_list->setClass('Contact'); // define the returning class
  5.         $contacts_list->addField('type',  'Contact TAype: ',  new TEntry('type'), 200);
  6.         $contacts_list->addField('value''Contact Value: ', new TEntry('value'), 200);
  7.         $contacts_list->addField('teste''Teste: ', new TEntry('teste'), 200);
  8. ?>


Não coloquei o código de um TMultifield criado por mim porque eu modifiquei essa classe para aceitar alinhar os campos lado-a-lado e colocar colspan. Se você precisar dessas funções posso colocar essa classe também.

AS

se pudesse postar a class
podemos criar um componete apartir das modificações que você, fez tenho certeza que sera util a muita gente
MS

Blz então, eu alterei pouca coisa é só procurar por "Mailson" que você encontrará as linhas que eu alterei. Segue o código:

Obs: O TMultifield.addField() terá mais alguns parâmetros não obrigatórios que trazem o default como padrão.

  1. <?php
  2. /**
  3.  * MultiField Widget: Takes a group of input fields and gives them the possibility to register many occurrences
  4.  *
  5.  * @version    1.0
  6.  * @package    widget_web
  7.  * @subpackage form
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2013 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class TMultiField extends TField implements IWidget {
  13.     private $fields;
  14.     private $objects;
  15.     private $height;
  16.     private $width;
  17.     private $className;
  18.     protected $formName;
  19.     /**
  20.      * Class Constructor
  21.      * @param $name Name of the widget
  22.      */
  23.     public function __construct($name) {
  24.         // define some default properties
  25.         self::setEditable(TRUE);
  26.         self::setName($name);
  27.         $this->fields = array();
  28.         $this->height 100;
  29.     }
  30.     /**
  31.      * Define the name of the form to wich the multifield is attached
  32.      * @param $name    A string containing the name of the form
  33.      * @ignore-autocomplete on
  34.      */
  35.     public function setFormName($name) {
  36.         parent::setFormName($name);
  37.         if ($this->fields) {
  38.             foreach ($this->fields as $name => $field) {
  39.                 $obj $field->{'field'};
  40.                 $obj->setFormName($this->formName);
  41.             }
  42.         }
  43.     }
  44.     /**
  45.      * Add a field to the MultiField
  46.      * @param $name   Widget's name
  47.      * @param $text   Widget's label
  48.      * @param $object Widget
  49.      * @param $size   Widget's size
  50.      * @param $inform Show the Widget in the form
  51.      */
  52.     public function addField($name$textTField $object$size$newRow true$colspan 1$inform TRUE) {
  53.         $obj = new StdClass;
  54.         $obj->name $name;
  55.         $obj->text $text;
  56.         $obj->field $object;
  57.         $obj->size $size;
  58.         //Mailson Datalan: Para controlar nova linha e colspan por componente
  59.         $obj->newRow $newRow;
  60.         $obj->colspan $colspan;
  61.         $obj->inform $inform;
  62.         $this->width += $size;
  63.         $this->fields[$name] = $obj;
  64.     }
  65.     /**
  66.      * Define the class for the Active Records returned by this component
  67.      * @param $class Class Name
  68.      */
  69.     public function setClass($class) {
  70.         $this->className $class;
  71.     }
  72.     /**
  73.      * Returns the class defined by the setClass() method
  74.      * @return the class for the Active Records returned by this component
  75.      */
  76.     public function getClass() {
  77.         return $this->className;
  78.     }
  79.     /**
  80.      * Define the MultiField content
  81.      * @param $objects A Collection of Active Records
  82.      */
  83.     public function setValue($objects) {
  84.         $this->objects $objects;
  85.         // This block is executed just to call the
  86.         // getters like get_virtual_property()
  87.         // inside the transaction (when the attribute)
  88.         // is set, and not after all (during the show())
  89.         if ($objects) {
  90.             foreach ($this->objects as $object) {
  91.                 foreach ($this->fields as $name => $obj) {
  92.                     $object->$name// regular attribute
  93.                     if ($obj->field instanceof TComboCombined) {
  94.                         $attribute $obj->field->getTextName();
  95.                         $object->$attribute// auxiliar attribute
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.     }
  101.     /**
  102.      * Return the post data
  103.      */
  104.     public function getPostData() {
  105.         if (isset($_POST[$this->name])) {
  106.             $val $_POST[$this->name];
  107.             $className $this->getClass() ? $this->getClass() : 'stdClass';
  108.             $decoded JSON_decode(stripslashes($val));
  109.             unset($items);
  110.             unset($obj_item);
  111.             $items = array();
  112.             foreach ($decoded as $std_object) {
  113.                 $obj_item = new $className;
  114.                 foreach ($std_object as $subkey => $value) {
  115.                     //substitui pq o ttable gera com quebra de linha no multifield
  116.                     //$obj_item->$subkey = URLdecode($value);
  117.                     $obj_item->$subkey str_replace("\n"''URLdecode($value));
  118.                 }
  119.                 $items[] = $obj_item;
  120.             }
  121.             return $items;
  122.         } else {
  123.             return '';
  124.         }
  125.     }
  126.     /**
  127.      * Define the MultiField height
  128.      * @param $height Height in pixels
  129.      */
  130.     public function setHeight($height) {
  131.         $this->height $height;
  132.     }
  133.     /**
  134.      * Show the widget at the screen
  135.      */
  136.     public function show() {
  137.         // include the needed libraries and styles
  138.         if ($this->fields) {
  139.             $table = new TTable;
  140.             $mdr = array(); // mandatory
  141.             $fields = array();
  142.             $i 0;
  143.             foreach ($this->fields as $name => $obj) {
  144.                 //Mailson Datalan: Para controlar nova linha por componente
  145.                 if ($obj->newRow)
  146.                     $row $table->addRow();
  147.                 $label = new TLabel($obj->text);
  148.                 if ($obj->inform) {
  149.                     $row->addCell($label);
  150.                     $cell $row->addCell($obj->field);
  151.                     //Mailson Datalan: Para controlar colpan por componente
  152.                     $cell->colspan $obj->colspan;
  153.                 }
  154.                 $fields[] = $name;
  155.                 $post_fields[$name] = 1;
  156.                 $obj->field->setName($this->name '_' $name);
  157.                 if (get_class($obj->field) == 'TComboCombined') {
  158.                     $fields[] = $obj->field->getTextName();
  159.                     $obj->field->setTextName($this->name '_' $obj->field->getTextName());
  160.                     $i++;
  161.                 }
  162.                 $i++;
  163.             }
  164.             $table->show();
  165.         }
  166.         // check whether the widget is non-editable
  167.         if (parent::getEditable()) {
  168.             // create three buttons to control the MultiField
  169.             $add = new TButton("{$this->name}btnStore");
  170.             $add->setLabel(TAdiantiCoreTranslator::translate('Register'));
  171.             //$add->setName("{$this->name}btnStore");
  172.             $add->setImage('ico_save.png');
  173.             $add->addFunction("mtf{$this->name}.addRowFromFormFields()");
  174.             $del = new TButton("{$this->name}btnDelete");
  175.             $del->setLabel(TAdiantiCoreTranslator::translate('Delete'));
  176.             $del->setImage('ico_delete.png');
  177.             $can = new TButton("{$this->name}btnCancel");
  178.             $can->setLabel(TAdiantiCoreTranslator::translate('Cancel'));
  179.             $can->setImage('ico_close.png');
  180.             $table = new TTable;
  181.             $row $table->addRow();
  182.             $row->addCell($add);
  183.             $row->addCell($del);
  184.             $row->addCell($can);
  185.             $table->show();
  186.         }
  187.         // create the MultiField Panel
  188.         $panel = new TElement('div');
  189.         $panel->{'class'} = "multifieldDiv";
  190.         $input = new THidden($this->name);
  191.         $panel->add($input);
  192.         // create the MultiField DataGrid Header
  193.         $table = new TTable;
  194.         $table->id "{$this->name}mfTable";
  195.         $head = new TElement('thead');
  196.         $table->add($head);
  197.         $row = new TTableRow;
  198.         $head->add($row);
  199.         // fill the MultiField DataGrid
  200.         foreach ($this->fields as $obj) {
  201.             $c $obj->text;
  202.             if (get_class($obj->field) == 'TComboCombined') {
  203.                 $row->addCell('ID');
  204.             }
  205.             $cell $row->addCell($c);
  206.             $cell->width $obj->size 'px';
  207.         }
  208.         $body = new TElement('tbody');
  209.         $table->add($body);
  210.         if ($this->objects) {
  211.             foreach ($this->objects as $obj) {
  212.                 if (isset($obj->id)) {
  213.                     $row = new TTableRow;
  214.                     $row->dbId $obj->id;
  215.                     $body->add($row);
  216.                 } else {
  217.                     $row = new TTableRow;
  218.                     $body->add($row);
  219.                 }
  220.                 foreach ($fields as $name) {
  221.                     $cell $row->addCell(is_null($obj->$name) ? '' $obj->$name);
  222.                     if (isset($this->fields[$name]->size)) {
  223.                         $cell->style 'width:' $this->fields[$name]->size 'px';
  224.                     }
  225.                 }
  226.             }
  227.         }
  228.         $panel->add($table);
  229.         $panel->show();
  230.         echo '<script type="text/javascript">';
  231.         echo "var mtf{$this->name};";
  232.         //echo '$(document).ready(function() {';
  233.         echo "mtf{$this->name} = new MultiField('{$this->name}mfTable',{$this->width},{$this->height});\n";
  234.         $s implode("','"$fields);
  235.         echo "mtf{$this->name}.formFieldsAlias = Array('{$s}');\n";
  236.         $fields implode("','{$this->name}_"$fields);
  237.         echo "mtf{$this->name}.formFieldsName = Array('{$this->name}_{$fields}');\n";
  238.         echo "mtf{$this->name}.formPostFields = Array();\n";
  239.         foreach ($post_fields as $col => $value) {
  240.             echo "mtf{$this->name}.formPostFields['{$col}'] = '$value';\n";
  241.         }
  242.         $mdr implode(','$mdr);
  243.         echo "mtf{$this->name}.formFieldsMandatory = Array({$mdr});\n";
  244.         echo "mtf{$this->name}.storeButton  = document.getElementsByName('{$this->name}btnStore')[0];\n";
  245.         echo "mtf{$this->name}.deleteButton = document.getElementsByName('{$this->name}btnDelete')[0];\n";
  246.         echo "mtf{$this->name}.cancelButton = document.getElementsByName('{$this->name}btnCancel')[0];\n";
  247.         echo "mtf{$this->name}.inputResult  = document.getElementsByName('{$this->name}')[0];\n";
  248.         //echo '});';
  249.         echo '</script>';
  250.     }
  251. }
  252. ?>
MS

Exemplo de um multifield criado com esta classe, fica quase igual.
  1. <?php
  2.         //Criação do multifield
  3.         $this->contatos_tpessoajur  = new TMultiField('contatos_tpessoajur');
  4.         $this->contatos_tpessoajur->setHeight(100);
  5.         $this->contatos_tpessoajur->setClass('tcontatojur'); // define the returning class
  6.         
  7.         //Criação dos componente que compõe o multifield
  8.         $id = new TEntry('id');        
  9.         $Nome = new TEntry('Nome');
  10.         $DDDFone = new TEntry('DDDFone');
  11.         $Fone = new TEntry('Fone');
  12.         $Ramal = new TEntry('Ramal');
  13.         $DDDCelular = new TEntry('DDDCelular');
  14.         $Celular = new TEntry('Celular');
  15.         $Email = new TEntry('Email');
  16.         $Setor = new TEntry('Setor');
  17.         $Aniversario = new TEntry('Aniversario');
  18.         $idtpessoajur = new TEntry('idtpessoajur');        
  19.         // define the sizes
  20.         $id->setSize(40);
  21.         $Nome->setSize(200);
  22.         $DDDFone->setSize(40);
  23.         $Fone->setSize(80);
  24.         $Ramal->setSize(40);
  25.         $DDDCelular->setSize(40);
  26.         $Celular->setSize(80);
  27.         $Email->setSize(284);
  28.         $Setor->setSize(220);
  29.         $Aniversario->setSize(80);
  30.         $idtpessoajur->setSize(40);
  31.         
  32.         //Personalização
  33.         $id->setEditable(false);
  34.         $this->contatos_tpessoajur->setHeight(250);
  35.         $this->contatos_tpessoajur->setClass('tcontatojur');
  36.         //Adição dos campos no multifield
  37.         $this->contatos_tpessoajur->addField('id''ID'$id40);
  38.         $this->contatos_tpessoajur->addField('Nome''Nome'$Nome200false);
  39.         $this->contatos_tpessoajur->addField('DDDFone''Fone'$DDDFone40false);
  40.         $this->contatos_tpessoajur->addField('Fone'''$Fone80false);
  41.         $this->contatos_tpessoajur->addField('Ramal''Ramal'$Ramal40false);
  42.         $this->contatos_tpessoajur->addField('DDDCelular''Celular'$DDDCelular40false);
  43.         $this->contatos_tpessoajur->addField('Celular'''$Celular80false);
  44.         $this->contatos_tpessoajur->addField('Email''Email'$Email200true3);
  45.         $this->contatos_tpessoajur->addField('Setor''Setor'$Setor140false5);
  46.         $this->contatos_tpessoajur->addField('Aniversario''Aniversário'$Aniversario80false3);    
  47. ?>
AS

Muito obrigado, logo eu posto o componente que to criando
ES

Oi Alexandre, dê uma olhada nesse componente adianti.com.br/forum/pt/view_658?tmultifieldpanel-12
Foi criado para esse propósito.

abs
Eliezer
WW

Pessoal, boa noite!

Estou utilizando um componente TSeekButton em um objeto TMultifield,
mas não estou conseguindo atribuir valores aos componentes TSeekButton e TEntry que estão no TMultifield.

Caso alguém tiver alguma solução, favor enviar.


Att.
Watson William
PD

Watson William
abre um topico novo e coloca o seu codigo para gente ver
WW

Ok, segue código.

  1. <?php
  2. class DadosGeraisTipoPessoaForm extends TPage
  3. {
  4.     protected $form// form
  5.     
  6.     /**
  7.      * Class constructor
  8.      * Creates the page and the registration form
  9.      */
  10.     function __construct()
  11.     {
  12.         parent::__construct();
  13.         
  14.         // creates the form
  15.         $this->form = new TForm('form_DadosGeraisTipoPessoa');
  16.         $this->form->class 'tform'// CSS class
  17.         
  18.         // add a table inside form
  19.         $table = new TTable;
  20.         $table-> width '100%';
  21.         $this->form->add($table);
  22.         
  23.         // add a row for the form title
  24.         $row $table->addRow();
  25.         $row->class 'tformtitle'// CSS class
  26.         $row->addCell( new TLabel('Dados Gerais - Tipo Pessoa') )->colspan 2;
  27.         
  28.         // create the form fields
  29.         $multifield = new TMultiField('contacts');
  30.         $multifield->setOrientation('horizontal');
  31.         // create the form fields
  32.         $dadosgerais_id                 = new TSeekButton('dadosgerais_id');
  33.         $tipopessoa_id                  = new TSeekButton('tipopessoa_id');
  34.         // define the sizes
  35.         $dadosgerais_id->setSize(200);
  36.         $tipopessoa_id->setSize(200);
  37.         //lookup dados gerais
  38.         $obj1 =  new TStandardSeek;        
  39.         $action1 = new TAction(array($obj1'onSetup'));        
  40.         $action1->setParameter('database','sollus');
  41.         $action1->setParameter('parent','form_DadosGeraisTipoPessoa');
  42.         $action1->setParameter('model','DadosGerais');
  43.         $action1->setParameter('display_field','nomeFantasia');
  44.         $action1->setParameter('receive_key','dadosgerais_id');
  45.         $action1->setParameter('receive_field','NomeFantasiaDadosGerais');
  46.         $dadosgerais_id->setAction($action1);      
  47.         
  48.         $multifield->setHeight(140);
  49.         $multifield->addField('dadosgerais_id''Dados Gerais'$dadosgerais_id280TRUE);
  50.         $multifield->addField('tipopessoa_id','Tipo Pessoa'$tipopessoa_id280TRUE);        
  51.         
  52.         // add a row for one field
  53.         $row=$table->addRow();
  54.         $row->addCell($lbl = new TLabel(''));
  55.         //$lbl->setFontStyle('b');
  56.         $row=$table->addRow();
  57.         $row->addCell($lbl = new TLabel(''));
  58.         $row->addCell($multifield );
  59.         
  60.         // create an action button (save)
  61.         $save_button=new TButton('save');
  62.         $save_button->setAction(new TAction(array($this'onSave')), _t('Save'));
  63.         $save_button->setImage('ico_save.png');
  64.  
  65.         // create an new button (edit with no parameters)
  66.         $new_button=new TButton('new');
  67.         $new_button->setAction(new TAction(array($this'onEdit')), _t('New'));
  68.         $new_button->setImage('ico_new.png');
  69.         $this->form->setFields(array($multifield$save_button$new_button));
  70.         
  71.         $buttons_box = new THBox;
  72.         $buttons_box->add($save_button);
  73.         $buttons_box->add($new_button);
  74.         
  75.         // add a row for the form action
  76.         $row $table->addRow();
  77.         $row->class 'tformaction'// CSS class
  78.         $row->addCell($buttons_box)->colspan 2;
  79.         
  80.         parent::add($this->form);
  81.     }
  82.     /**
  83.      * method onSave()
  84.      * Executed whenever the user clicks at the save button
  85.      */
  86.     function onSave()
  87.     {
  88.         try
  89.         {
  90.             // open a transaction with database 'sollus'
  91.             TTransaction::open('sollus');
  92.             
  93.             // get the form data into an active record DadosGeraisTipoPessoa
  94.             $object $this->form->getData('DadosGeraisTipoPessoa');
  95.             
  96.             $this->form->validate(); // form validation
  97.                         
  98.             // get the contacts
  99.             if ($object->contacts)
  100.             {
  101.                 foreach ($object->contacts as $contact)
  102.                 {
  103.                     $dadosGeraisTipoPessoa = new DadosGeraisTipoPessoa();
  104.                     $dadosGeraisTipoPessoa->dadosgerais_id $contact->dadosgerais_id;
  105.                     $dadosGeraisTipoPessoa->tipopessoa_id $contact->tipopessoa_id;
  106.                     
  107.                     $dadosGeraisTipoPessoa->store(); // stores the object
  108.                 }
  109.             }
  110.             
  111.             $this->form->setData($object); // keep form data
  112.             
  113.             TTransaction::close(); // close the transaction
  114.             
  115.             // shows the success message
  116.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  117.         }
  118.         catch (Exception $e// in case of exception
  119.         {
  120.             // shows the exception error message
  121.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  122.             
  123.             $this->form->setData$this->form->getData() ); // keep form data
  124.             
  125.             // undo all pending operations
  126.             TTransaction::rollback();
  127.         }
  128.     }
  129.     
  130.     /**
  131.      * method onEdit()
  132.      * Executed whenever the user clicks at the edit button da datagrid
  133.      */
  134.     function onEdit($param)
  135.     {
  136.         try
  137.         {
  138.             if (isset($param['key']))
  139.             {
  140.                 // get the parameter $key
  141.                 $key=$param['key'];
  142.                 
  143.                 // open a transaction with database 'sollus'
  144.                 TTransaction::open('sollus');
  145.                 
  146.                 // instantiates object DadosGeraisTipoPessoa
  147.                 $object = new DadosGeraisTipoPessoa($key);
  148.                 
  149.                 // fill the form with the active record data
  150.                 $this->form->setData($object);
  151.                 
  152.                 // close the transaction
  153.                 TTransaction::close();
  154.             }
  155.             else
  156.             {
  157.                 $this->form->clear();
  158.             }
  159.         }
  160.         catch (Exception $e// in case of exception
  161.         {
  162.             // shows the exception error message
  163.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  164.             
  165.             // undo all pending operations
  166.             TTransaction::rollback();
  167.         }
  168.     }
  169. }
  170. ?>
PD

Oi Watson,

Os campos da multifield sempre são precedidos do próprio nome da multifield. Assim, tente usar "contacts_dadosgerais_id" e não somente "dadosgerais_id" em lugares como o "receive_key" ;-)

Att,
Pablo
WW

Pablo, muito obrigado.