Alterar layout de um QuickForm Boa tarde, Pessoal estou colocando em anexo o form que desenvolvi com o THtmlRenderer, gostaria de aplicar este layout utilizando um QuickForm, se observarem realizei com o HTML, para aproximar o Label dos Inputs, e também para dentro do inputs concatenar variáveis. Seria possível isso com um QuickForm?...
EL
Alterar layout de um QuickForm  
Fechado
Boa tarde,
Pessoal estou colocando em anexo o form que desenvolvi com o THtmlRenderer, gostaria de aplicar este layout utilizando um QuickForm, se observarem realizei com o HTML, para aproximar o Label dos Inputs, e também para dentro do inputs concatenar variáveis.
Seria possível isso com um QuickForm?

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


EL

Este é o código do QuickForm o que sugerem?

 
  1. <?php
  2. /**
  3. * OrdemServicoForm Registration
  4. * @author Eduardo Lopes
  5. */
  6. class OrdemServicoForm extends TPage
  7. {
  8. protected $form; // form
  9. // Standard form methods
  10. use Adianti\\Base\\AdiantiStandardFormTrait;
  11. /*** Class constructor and creates the page and the registration form ***/
  12. function __construct()
  13. {
  14. parent::__construct();
  15. // load the styles
  16. TPage::include_css('app/resources/styles.css');
  17. // defines the database and defines the active record
  18. $this->setDatabase('dbprod');
  19. $this->setActiveRecord('OrdemServico');
  20. // creates the form and change CSS class and change style
  21. $this->form = new TQuickForm('form_OrdemServico');
  22. $this->form->class = 'tform';
  23. $this->form->style = 'display: table;width:100%';
  24. // define the form title
  25. $this->form->setFormTitle('Ordem de Servico');
  26. // create the form fields
  27. $NR_SEQUENCIA = new TEntry('NR_SEQUENCIA');
  28. $NR_SEQ_LOCALIZACAO = new TEntry('NR_SEQ_LOCALIZACAO');
  29. $LOCALIZACAO = new TEntry('local_name');
  30. $NR_SEQ_EQUIPAMENTO = new TEntry('NR_SEQ_EQUIPAMENTO');
  31. $EQUIPAMENTO = new TEntry('equipamento_name');
  32. $CD_PESSOA_SOLICITANTE = new TEntry('CD_PESSOA_SOLICITANTE');
  33. $NOME_PESSOA = new TEntry('pessoa_name');
  34. $DT_ORDEM_SERVICO = new TEntry('DT_ORDEM_SERVICO');
  35. $DS_DANO_BREVE = new TEntry('DS_DANO_BREVE');
  36. $DS_DANO = new TText('DS_DANO');
  37. $SATISFACAO = new TRadioGroup('IE_GRAU_SATISFACAO');
  38. $SATISFACAO->setLayout('horizontal');
  39. $items = array();
  40. $items ['O'] ='Ótimo';
  41. $items ['B'] ='Bom';
  42. $items ['A'] ='Ruim';
  43. $items ['D'] ='Péssimo';
  44. $SATISFACAO->addItems($items);
  45. // add the fields
  46. $this->form->addQuickField('Número', $NR_SEQUENCIA, 200 );
  47. $this->form->addQuickField('Localização', $NR_SEQ_LOCALIZACAO, 200 );
  48. $this->form->addQuickField('Nr Seq Localizacao', $LOCALIZACAO, 200 );
  49. $this->form->addQuickField('Nr Seq Equipamento', $NR_SEQ_EQUIPAMENTO, 200 );
  50. $this->form->addQuickField('Nr Seq Equipamento', $EQUIPAMENTO, 200 );
  51. $this->form->addQuickField('Cd Pessoa Solicitante', $CD_PESSOA_SOLICITANTE, 200 );
  52. $this->form->addQuickField('Solicitante', $NOME_PESSOA, 200 );
  53. $this->form->addQuickField('Data', $DT_ORDEM_SERVICO, 200 );
  54. $this->form->addQuickField('Descrição', $DS_DANO_BREVE, 400 );
  55. $this->form->addQuickField('Descrição', $DS_DANO, 200 );
  56. $DS_DANO->setSize(400, 100);
  57. $this->form->addQuickField('Grau Satisfação', $SATISFACAO, 200 );
  58. if (!empty($NR_SEQUENCIA))
  59. {
  60. $NR_SEQUENCIA->setEditable(FALSE);
  61. }
  62. // create the form actions
  63. $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  64. $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onEdit')), 'bs:plus-sign green');
  65. // vertical box container
  66. $container = new TVBox;
  67. $container->style = 'width: 100%';
  68. $container->add($this->form);
  69. parent::add($container);
  70. }
  71. }
  72. ?>
NR

Eduardo, você pode modificar o layout do formulário através de CSS. Esse código que você postou já faz a inclusão de um CSS:
 
  1. <?php
  2. TPage::include_css('app/resources/styles.css');
  3. ?>


Note que também é possível definir a classe do formulário:
 
  1. <?php
  2. $this->form->class = 'tform';
  3. ?>


Para concatenar variáveis você pode modificar a função onEdit adicionando o seguinte, por exemplo:
 
  1. <?php
  2. $object->local_name = $object->local_id . ' - ' . $object->descricao;
  3. ?>


Outra possibilidade seria criar uma função no model correspondente, do tipo:
 
  1. <?php
  2. function get_local_name()
  3. {
  4. return $this->id . ' - ' . $this->descricao;
  5. }
  6. ?>

EL

Boa tarde,
Nataniel obrigado pelo retorno tentei via CSS como você mencionou, mas achei inviável por conta do TQuickForm inserir alguns estilos em linha, optei por deixar o código chamando um HTML e o QuickForm da seguinte maneira, para brincar com o HTML:

 
  1. <?php
  2. /**
  3. * OrdemServicoForm Registration
  4. * @author Eduardo Lopes
  5. */
  6. class OrdemServicoForm extends TPage
  7. {
  8. private $quickform;
  9. function __construct()
  10. {
  11. parent::__construct();
  12. // load the styles
  13. TPage::include_css('app/resources/styles.css');
  14. // create a quick form with action buttons
  15. $this->form = new TQuickForm;
  16. $this->form->class = 'tform';
  17. // create the form fields ocultos
  18. $NR_SEQUENCIA = new THidden('NR_SEQUENCIA');
  19. // create the form fields
  20. $SATISFACAO = new TRadioGroup('IE_GRAU_SATISFACAO');
  21. $SATISFACAO->setLayout('horizontal');
  22. $items = array();
  23. $items ['O'] ='<img src="app/images/smile/otimo.png" height="100" width="100">';
  24. $items ['B'] ='<img src="app/images/smile/bom.png" height="100" width="100">';
  25. $items ['A'] ='<img src="app/images/smile/ruim.png" height="100" width="100">';
  26. $items ['D'] ='<img src="app/images/smile/pessimo.png" height="100" width="100">';
  27. $SATISFACAO->addItems($items);
  28. // add the fields
  29. $this->form->addQuickField('Grau de Satisfação:', $SATISFACAO);
  30. // add the fields ocultos
  31. $this->form->addQuickField('Número', $NR_SEQUENCIA);
  32. // create the form actions
  33. $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  34. try
  35. {
  36. // create the HTML Renderer
  37. $this->html = new THtmlRenderer('app/resources/ordem.html');
  38. $ordem = new OrdemServico();
  39. // define replacements for the main section
  40. $replace = array();
  41. $replace['Numero'] = $ordem->NR_SEQUENCIA;
  42. $replace['Solicitante'] = $ordem->CD_PESSOA_SOLICITANTE;
  43. $replace['Pessoa'] = $ordem->pessoa_name;
  44. $replace['Seq_Local'] = $ordem->NR_SEQ_LOCALIZACAO;
  45. $replace['Local'] = $ordem->local_name;
  46. $replace['Seq_Equip'] = $ordem->NR_SEQ_EQUIPAMENTO;
  47. $replace['Equipamento'] = $ordem->equipamento_name;
  48. $replace['Descricao'] = $ordem->DS_DANO_BREVE;
  49. $replace['Dano'] = $ordem->DS_DANO;
  50. // replace the main section variables
  51. $this->html->enableSection('main', $replace);
  52. // Table wrapper (form and HTML)
  53. $table = new TTable;
  54. $table->style = 'width: 100%';
  55. $table->addRow()->addCell($this->html);
  56. $table->addRow()->addCell($this->form);
  57. parent::add($table);
  58. TTransaction::close();
  59. }
  60. catch (Exception $e)
  61. {
  62. new TMessage('error', $e->getMessage());
  63. }
  64. }
  65. function onLoad($param)
  66. {
  67. // Alterar icone no produto.form.xml
  68. // <icon>ico_next.png</icon>
  69. $key = $param['key'];
  70. $this->onEdit( array('key'=>$key));
  71. }
  72. function onEdit($param)
  73. {
  74. try
  75. {
  76. if (isset($param['key']))
  77. {
  78. // get the parameter $key
  79. $key=$param['key'];
  80. TTransaction::open('dbprod'); // open a transaction with database 'samples'
  81. $object = new OrdemServico($key); // instantiates object City
  82. $ordem = new OrdemServico($key);
  83. // define replacements for the main section
  84. $replace = array();
  85. $replace['Numero'] = $ordem->NR_SEQUENCIA;
  86. $replace['Solicitante'] = $ordem->CD_PESSOA_SOLICITANTE;
  87. $replace['Pessoa'] = $ordem->pessoa_name;
  88. $replace['Seq_Local'] = $ordem->NR_SEQ_LOCALIZACAO;
  89. $replace['Local'] = $ordem->local_name;
  90. $replace['Seq_Equip'] = $ordem->NR_SEQ_EQUIPAMENTO;
  91. $replace['Equipamento'] = $ordem->equipamento_name;
  92. $replace['Descricao'] = $ordem->DS_DANO_BREVE;
  93. $replace['Dano'] = $ordem->DS_DANO;
  94. $this->html->enableSection('main', $replace);
  95. $this->form->setData($object); // fill the form with the active record data
  96. TTransaction::close(); // close the transaction
  97. }
  98. else
  99. {
  100. $this->form->clear();
  101. }
  102. }
  103. catch (Exception $e) // in case of exception
  104. {
  105. // shows the exception error message
  106. new TMessage('error', $e->getMessage());
  107. // undo all pending operations
  108. TTransaction::rollback();
  109. }
  110. }
  111. function onSave()
  112. {
  113. try
  114. {
  115. $this->form->setData($data = $this->form->getData());
  116. TSession::setValue('hospital', (array) $data);
  117. TTransaction::open('dbprod'); // abre uma transação
  118. $dbh = TTransaction::get(); // obtém a conexão
  119. $dbh->exec(" UPDATE MAN_ORDEM_SERVICO SET IE_GRAU_SATISFACAO = '$data->IE_GRAU_SATISFACAO' where NR_SEQUENCIA = $data->NR_SEQUENCIA ");
  120. $this->form->setData($data); // fill the form with the active record data
  121. $ordem = new OrdemServico($data->NR_SEQUENCIA);
  122. // define replacements for the main section
  123. $replace = array();
  124. $replace['Numero'] = $ordem->NR_SEQUENCIA;
  125. $replace['Solicitante'] = $ordem->CD_PESSOA_SOLICITANTE;
  126. $replace['Pessoa'] = $ordem->pessoa_name;
  127. $replace['Seq_Local'] = $ordem->NR_SEQ_LOCALIZACAO;
  128. $replace['Local'] = $ordem->local_name;
  129. $replace['Seq_Equip'] = $ordem->NR_SEQ_EQUIPAMENTO;
  130. $replace['Equipamento'] = $ordem->equipamento_name;
  131. $replace['Descricao'] = $ordem->DS_DANO_BREVE;
  132. $replace['Dano'] = $ordem->DS_DANO;
  133. $this->html->enableSection('main', $replace);
  134. new TMessage('info', 'Obrigado por contribuir com a sua resposta !');
  135. TTransaction::close(); // close transaction
  136. }
  137. catch (Exception $e) // in case of exception
  138. {
  139. // shows the exception error message
  140. new TMessage('error', $e->getMessage());
  141. // undo all pending operations
  142. TTransaction::rollback();
  143. }
  144. }
  145. }
  146. ?>


Queria enxugar o código agora, se alguém tiver sugestões agradeço.
NR

Eduardo, para diminuir um pouco o código você poderia criar uma função pra preencher e retornar esse array $replaces, aí ao invés de repetir o mesmo trecho toda vez você passa a chamar a função criada:
 
  1. <?php
  2. function replaces($ordem)
  3. {
  4. $replace = array();
  5. $replace['Numero'] = $ordem->NR_SEQUENCIA;
  6. $replace['Solicitante'] = $ordem->CD_PESSOA_SOLICITANTE;
  7. ...
  8. return $replace;
  9. }
  10. function onEdit($param)
  11. {
  12. ...
  13. $replace = $this->replaces($ordem);
  14. ...
  15. }
  16. ?>
YC

Bom dia Eduardo!

Fiquei muito interessado nesses form's personalizados e gostaria de me aprofundar um pouco mais.
Você poderia postar o código do seu app/resources/ordem.html. Quero saber como é que faz essa identificação das variáveis no input
EL

Bom dia Yanko!

Desculpe a demora no retorno, só visualizei ontem.

<div style="width: 100%"> <div style="clear:both"> <form class="tform" style="display: table;width:100%" enctype="multipart/form-data" name="form_OrdemServico" id="form_OrdemServico" method="post"> <table width="100%"> <tbody><tr class="tformtitle"><td colspan="2"><label>Ordem de Servico</label></td></tr> <tr> <td align=right width="10%"><label>Número:</label></td> <td><input disabled="disabled" class="tfield_disabled" name="NR_SEQUENCIA" value={$Numero} style="width:200px;" readonly="1" onmouseover="style.cursor='default'" type="text"></td> </tr> <tr> <td align=right><label>Solicitante:</label></td> <td><input disabled="disabled" class="tfield_disabled" name="NR_SEQ_LOCALIZACAO" value="{$Solicitante} - {$Pessoa}" style="width:200px;" type="text"></td> </tr> <tr> <td align=right><label>Localização:</label></td> <td><input disabled="disabled" class="tfield_disabled" name="local_name" value="{$Seq_Local} - {$Local}" style="width:50%;" type="text"></td> </tr> <tr> <td align=right><label>Equipamento:</label></td> <td><input disabled="disabled" class="tfield_disabled" name="NR_SEQ_EQUIPAMENTO" value="{$Seq_Equip} - {$Equipamento}" style="width:50%;" type="text"></td> </tr> <tr> <td align=right><label>Descrição:</label></td> <td><input disabled="disabled" class="tfield_disabled" name="equipamento_name" value="{$Descricao}" style="width:50%;" type="text"></td> </tr> <tr> <td align=right><label>Dano:</label></td> <td><textarea disabled="disabled" class="tfield_disabled" name="DS_DANO" style="width:50%;;height:100px">{$Dano}</textarea></td> </tr> </tbody> </table> </form> </div> </div>
JC

Eduardo Lopes, entra em contato comigo por favor,preciso muito tirar uma duvida em relação a esse codigo!!!