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 Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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, $text, TField $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. //Criação dos componente que compõe o multifield
  7. $id = new TEntry('id');
  8. $Nome = new TEntry('Nome');
  9. $DDDFone = new TEntry('DDDFone');
  10. $Fone = new TEntry('Fone');
  11. $Ramal = new TEntry('Ramal');
  12. $DDDCelular = new TEntry('DDDCelular');
  13. $Celular = new TEntry('Celular');
  14. $Email = new TEntry('Email');
  15. $Setor = new TEntry('Setor');
  16. $Aniversario = new TEntry('Aniversario');
  17. $idtpessoajur = new TEntry('idtpessoajur');
  18. // define the sizes
  19. $id->setSize(40);
  20. $Nome->setSize(200);
  21. $DDDFone->setSize(40);
  22. $Fone->setSize(80);
  23. $Ramal->setSize(40);
  24. $DDDCelular->setSize(40);
  25. $Celular->setSize(80);
  26. $Email->setSize(284);
  27. $Setor->setSize(220);
  28. $Aniversario->setSize(80);
  29. $idtpessoajur->setSize(40);
  30. //Personalização
  31. $id->setEditable(false);
  32. $this->contatos_tpessoajur->setHeight(250);
  33. $this->contatos_tpessoajur->setClass('tcontatojur');
  34. //Adição dos campos no multifield
  35. $this->contatos_tpessoajur->addField('id', 'ID', $id, 40);
  36. $this->contatos_tpessoajur->addField('Nome', 'Nome', $Nome, 200, false);
  37. $this->contatos_tpessoajur->addField('DDDFone', 'Fone', $DDDFone, 40, false);
  38. $this->contatos_tpessoajur->addField('Fone', '', $Fone, 80, false);
  39. $this->contatos_tpessoajur->addField('Ramal', 'Ramal', $Ramal, 40, false);
  40. $this->contatos_tpessoajur->addField('DDDCelular', 'Celular', $DDDCelular, 40, false);
  41. $this->contatos_tpessoajur->addField('Celular', '', $Celular, 80, false);
  42. $this->contatos_tpessoajur->addField('Email', 'Email', $Email, 200, true, 3);
  43. $this->contatos_tpessoajur->addField('Setor', 'Setor', $Setor, 140, false, 5);
  44. $this->contatos_tpessoajur->addField('Aniversario', 'Aniversário', $Aniversario, 80, false, 3);
  45. ?>
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. * Class constructor
  7. * Creates the page and the registration form
  8. */
  9. function __construct()
  10. {
  11. parent::__construct();
  12. // creates the form
  13. $this->form = new TForm('form_DadosGeraisTipoPessoa');
  14. $this->form->class = 'tform'; // CSS class
  15. // add a table inside form
  16. $table = new TTable;
  17. $table-> width = '100%';
  18. $this->form->add($table);
  19. // add a row for the form title
  20. $row = $table->addRow();
  21. $row->class = 'tformtitle'; // CSS class
  22. $row->addCell( new TLabel('Dados Gerais - Tipo Pessoa') )->colspan = 2;
  23. // create the form fields
  24. $multifield = new TMultiField('contacts');
  25. $multifield->setOrientation('horizontal');
  26. // create the form fields
  27. $dadosgerais_id = new TSeekButton('dadosgerais_id');
  28. $tipopessoa_id = new TSeekButton('tipopessoa_id');
  29. // define the sizes
  30. $dadosgerais_id->setSize(200);
  31. $tipopessoa_id->setSize(200);
  32. //lookup dados gerais
  33. $obj1 = new TStandardSeek;
  34. $action1 = new TAction(array($obj1, 'onSetup'));
  35. $action1->setParameter('database','sollus');
  36. $action1->setParameter('parent','form_DadosGeraisTipoPessoa');
  37. $action1->setParameter('model','DadosGerais');
  38. $action1->setParameter('display_field','nomeFantasia');
  39. $action1->setParameter('receive_key','dadosgerais_id');
  40. $action1->setParameter('receive_field','NomeFantasiaDadosGerais');
  41. $dadosgerais_id->setAction($action1);
  42. $multifield->setHeight(140);
  43. $multifield->addField('dadosgerais_id', 'Dados Gerais', $dadosgerais_id, 280, TRUE);
  44. $multifield->addField('tipopessoa_id','Tipo Pessoa', $tipopessoa_id, 280, TRUE);
  45. // add a row for one field
  46. $row=$table->addRow();
  47. $row->addCell($lbl = new TLabel(''));
  48. //$lbl->setFontStyle('b');
  49. $row=$table->addRow();
  50. $row->addCell($lbl = new TLabel(''));
  51. $row->addCell($multifield );
  52. // create an action button (save)
  53. $save_button=new TButton('save');
  54. $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
  55. $save_button->setImage('ico_save.png');
  56. // create an new button (edit with no parameters)
  57. $new_button=new TButton('new');
  58. $new_button->setAction(new TAction(array($this, 'onEdit')), _t('New'));
  59. $new_button->setImage('ico_new.png');
  60. $this->form->setFields(array($multifield, $save_button, $new_button));
  61. $buttons_box = new THBox;
  62. $buttons_box->add($save_button);
  63. $buttons_box->add($new_button);
  64. // add a row for the form action
  65. $row = $table->addRow();
  66. $row->class = 'tformaction'; // CSS class
  67. $row->addCell($buttons_box)->colspan = 2;
  68. parent::add($this->form);
  69. }
  70. /**
  71. * method onSave()
  72. * Executed whenever the user clicks at the save button
  73. */
  74. function onSave()
  75. {
  76. try
  77. {
  78. // open a transaction with database 'sollus'
  79. TTransaction::open('sollus');
  80. // get the form data into an active record DadosGeraisTipoPessoa
  81. $object = $this->form->getData('DadosGeraisTipoPessoa');
  82. $this->form->validate(); // form validation
  83. // get the contacts
  84. if ($object->contacts)
  85. {
  86. foreach ($object->contacts as $contact)
  87. {
  88. $dadosGeraisTipoPessoa = new DadosGeraisTipoPessoa();
  89. $dadosGeraisTipoPessoa->dadosgerais_id = $contact->dadosgerais_id;
  90. $dadosGeraisTipoPessoa->tipopessoa_id = $contact->tipopessoa_id;
  91. $dadosGeraisTipoPessoa->store(); // stores the object
  92. }
  93. }
  94. $this->form->setData($object); // keep form data
  95. TTransaction::close(); // close the transaction
  96. // shows the success message
  97. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  98. }
  99. catch (Exception $e) // in case of exception
  100. {
  101. // shows the exception error message
  102. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  103. $this->form->setData( $this->form->getData() ); // keep form data
  104. // undo all pending operations
  105. TTransaction::rollback();
  106. }
  107. }
  108. /**
  109. * method onEdit()
  110. * Executed whenever the user clicks at the edit button da datagrid
  111. */
  112. function onEdit($param)
  113. {
  114. try
  115. {
  116. if (isset($param['key']))
  117. {
  118. // get the parameter $key
  119. $key=$param['key'];
  120. // open a transaction with database 'sollus'
  121. TTransaction::open('sollus');
  122. // instantiates object DadosGeraisTipoPessoa
  123. $object = new DadosGeraisTipoPessoa($key);
  124. // fill the form with the active record data
  125. $this->form->setData($object);
  126. // close the transaction
  127. TTransaction::close();
  128. }
  129. else
  130. {
  131. $this->form->clear();
  132. }
  133. }
  134. catch (Exception $e) // in case of exception
  135. {
  136. // shows the exception error message
  137. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  138. // undo all pending operations
  139. TTransaction::rollback();
  140. }
  141. }
  142. }
  143. ?>
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.