PD
Alterando o estilo de componentes dinamicamente
Fechado
Neste exemplo, vamos demonstrar como alterar o estilo de um elemento (TLabel) após a postagem do formulário. Nesta página, vamos criar um formulário simples somente com dois campos e um botão "Salvar" conectado ao método onSave(). Quando o usuário clicar no botão "Salvar", o método onSave() é executado. Então, alteramos o estilo do atributo label Neste atributo, temos um objeto TLabel, parte do formulário. O estilo é alterado por meio dos métodos: setFontStyle(), que habilita bold, itálico ou sublinhado; e setFontColor() que altera a cor da fonte.
<?php/** * ChangeStyleView report * * @version 1.0 * @package samples * @subpackage tutor * @author Pablo Dall'Oglio * @copyright Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br) * @license http://www.adianti.com.br/framework-license */class ChangeStyleView extends TPage{ private $form; private $label1; private $label2; /** * Class constructor * Creates the page and the registration form */ function __construct() { parent::__construct(); // create the form $this->form = new TForm; $table = new TTable; $this->form->add($table); $this->label1 = new TLabel('Object 1:'); $this->label2 = new TLabel('Object 2:'); // create the form fields $field1 = new TEntry('field1'); $field2 = new TEntry('field2'); // add a row for one field $row=$table->addRow(); $row->addCell($this->label1); $cell = $row->addCell( $field1 ); // add a row for one field $row=$table->addRow(); $row->addCell($this->label2); $cell = $row->addCell( $field2 ); // creates the action button $button1=new TButton('action1'); $button1->setAction(new TAction(array($this, 'onSave')), 'Save'); $button1->setImage('ico_save.png'); // define wich are the form fields $this->form->setFields(array($field1, $field2, $button1)); // add a row for the button $row=$table->addRow(); $row->addCell($button1); // add the form inside the page parent::add($this->form); } /** * method onSave() * Executed whenever the user clicks at the Save button */ function onSave() { try { $data = $this->form->getData(); $this->form->setData($data); $this->label1->setFontStyle('b'); $this->label1->setFontColor('red'); } catch (Exception $e) // in case of exception { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); } }}?>