Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Slider Vertical Olá, Tenho uma tarefa para uma entrevista de emprego que gostaria de desenvolver usando o framework. Todavia é solicitado que o formulário tenha vários campos do tipo slider verticais, tal como (https://jqueryui.com/slider/#multiple-vertical), porém no framework, até onde vi, só tem slide horizontal. Gostaria muito se alguém pudesse indicar o melhor caminho a seguir nesse caso. Abs...
FC
Slider Vertical  
Fechado
Olá,

Tenho uma tarefa para uma entrevista de emprego que gostaria de desenvolver usando o framework.
Todavia é solicitado que o formulário tenha vários campos do tipo slider verticais, tal como (https://jqueryui.com/slider/#multiple-vertical), porém no framework, até onde vi, só tem slide horizontal.
Gostaria muito se alguém pudesse indicar o melhor caminho a seguir nesse caso.

Abs,

Felipe

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (3)


FC

Olá Xará o primeiro salário será meu. ou como fazemos aqui no serviço vai perder o ticket rsrss

Essa alteração exige um pouco de conhecimento em JavaScript porém como o Framework é fantástico fica fácil fazer modificações lembrando que a solução que te passarei deveria seguir algumas regras de extensibilidade porém como há a necessidade de modificar o Java Script quando tiver atualização do core irá precisar rever.


Será necessário alterar a classe TSlider e o arquivo Java Sript components.min.js

Arquivo components.min.js JavaScript troque essa função note que acrescentei uma variável
function tslider_start(a, b, c, d, e, f) { $(function() { $(a + "_div").slider({ orientation: f, value: b, min: c, max: d, step: e, slide: function(b, c) { $(a).val(c.value) } }) }) }


Ok na Classe TSlider ficará assim
  1. <?php
  2. Namespace Adianti\\Widget\\Form;
  3. use Adianti\\Widget\\Form\\AdiantiWidgetInterface;
  4. use Adianti\\Widget\\Base\\TElement;
  5. use Adianti\\Widget\\Base\\TScript;
  6. use Adianti\\Widget\\Form\\TField;
  7. /**
  8.  * Slider Widget
  9.  *
  10.  * @version    2.0
  11.  * @package    widget
  12.  * @subpackage form
  13.  * @author     Pablo Dall'Oglio
  14.  * @copyright  Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  15.  * @license    http://www.adianti.com.br/framework-license
  16.  */
  17. class TSlider extends TField implements AdiantiWidgetInterface
  18. {
  19.     protected $id;
  20.     private $min;
  21.     private $max;
  22.     private $step;
  23.     private $direction;
  24.     
  25.     /**
  26.      * Class Constructor
  27.      * @param $name Name of the widget
  28.      */
  29.     public function __construct($name)
  30.     {
  31.         parent::__construct($name);
  32.         $this->id   'tslider_'.uniqid();
  33.     }
  34.     
  35.     /**
  36.      * Define the field's range
  37.      * @param $min Minimal value
  38.      * @param $max Maximal value
  39.      * @param $step Step value
  40.      */
  41.     public function setRange($min$max$step$direction)
  42.     {
  43.         $this->min $min;
  44.         $this->max $max;
  45.         $this->step $step;
  46.         $this->value $min;
  47.         $this->direction '"'.$direction.'"';
  48.         
  49.     }
  50.     
  51.     /**
  52.      * Enable the field
  53.      * @param $form_name Form name
  54.      * @param $field Field name
  55.      */
  56.     public static function enableField($form_name$field)
  57.     {
  58.         TScript::create" tslider_enable_field('{$form_name}', '{$field}'); " );
  59.     }
  60.     
  61.     /**
  62.      * Disable the field
  63.      * @param $form_name Form name
  64.      * @param $field Field name
  65.      */
  66.     public static function disableField($form_name$field)
  67.     {
  68.         TScript::create" tslider_disable_field('{$form_name}', '{$field}'); " );
  69.     }
  70.     
  71.     /**
  72.      * Shows the widget at the screen
  73.      */
  74.     public function show()
  75.     {
  76.         // define the tag properties
  77.         $this->tag-> name  $this->name;    // TAG name
  78.         $this->tag-> value $this->value;   // TAG value
  79.         $this->tag-> type  'text';         // input type
  80.         $this->tag-> style "width:{$this->size}px";  // size
  81.         
  82.         if ($this->id)
  83.         {
  84.             $this->tag->{'id'} = $this->id;
  85.         }
  86.         
  87.         // verify if the widget is editable
  88.         if (parent::getEditable())
  89.         {
  90.             $this->tag-> readonly "1";
  91.             $this->tag-> style "width:40px;-moz-user-select:none;border:0;text-align:center";
  92.             
  93.             $div = new TElement('div');
  94.             $div-> id $this->id.'_div';
  95.             $div-> style "width:{$this->size}px";
  96.             
  97.             $main_div = new TElement('div');
  98.             $main_div-> style="text-align:center;width:{$this->size}px";
  99.             
  100.             TScript::create(" tslider_start( '#{$this->id}', {$this->value}{$this->min}{$this->max}{$this->step}{$this->direction} ); ");
  101.             
  102.             $main_div->add($this->tag);
  103.             $main_div->add($div);
  104.             $main_div->show();
  105.         }
  106.         else
  107.         {
  108.             $this->tag-> readonly "1";
  109.             $this->tag->{'class'} = 'tfield_disabled'// CSS
  110.             $this->tag-> style "width:40px;-moz-user-select:none;";
  111.             $this->tag-> onmouseover "style.cursor='default'";
  112.             $this->tag->show();
  113.         }
  114.     }
  115.     
  116.     /**
  117.      * Set the value
  118.      */
  119.     public function setValue($value)
  120.     {
  121.         parent::setValue( (int) $value);
  122.     }
  123. }
  124. ?>


agora o que nós fizemos acrescentamos uma variável que iremos dizer a orientação do Slider conforme a documentação
https://api.jqueryui.com/slider/

Eu usei um form do tutor para testar:


  1. <?php
  2. /**
  3.  * FormCustomView
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class FormCustomView extends TPage
  13. {
  14.     private $form;
  15.     
  16.     /**
  17.      * Class constructor
  18.      * Creates the page
  19.      */
  20.     function __construct()
  21.     {
  22.         parent::__construct();
  23.         
  24.         // create the notebook
  25.         $notebook = new TNotebook(620340);
  26.         
  27.         // create the form
  28.         $this->form = new TForm;
  29.         
  30.         // creates the notebook page
  31.         $table = new TTable;
  32.         
  33.         // add the notebook inside the form
  34.         $this->form->add($table);
  35.         
  36.         // adds the notebook page
  37.         $notebook->appendPage('Input elements'$this->form);
  38.         
  39.         // create the form fields
  40.         $field1  = new TEntry('field1');
  41.         $field2  = new TEntry('field2');
  42.         $field3  = new TEntry('field3');
  43.         $field4  = new TEntry('field4');
  44.         $field5  = new TPassword('field5');
  45.         $field6  = new TDate('field6');
  46.         $field7  = new TSpinner('field7');
  47.         $field8  = new TSlider('field8');
  48.         $field9 = new TText('field9');
  49.         
  50.         $field1->setTip('Tip for field 1');
  51.         $field2->setTip('Tip for field 2');
  52.         $field3->setTip('Tip for field 3');
  53.         $field4->setTip('Tip for field 4');
  54.         $field5->setTip('Tip for field 5');
  55.         $field6->setTip('Tip for field 6');
  56.         $field7->setTip('Tip for field 7');
  57.         $field8->setTip('Tip for field 8');
  58.         $field9->setTip('Tip for field 9');
  59.         
  60.         $field2->setValue('123');
  61.         $field2->setEditable(FALSE);
  62.         $field3->setMask('99.999-999');
  63.         $field4->setMaxLength(10);
  64.         $field6->setSize(100);
  65.         $field7->setRange(0,100,10);
  66.         $field8->setSize(10);//alterado o tamanho do slider 
  67.         $field8->setRange(0,100,5,'vertical');//acresentado a variavel direction
  68.         $field7->setValue(30);
  69.         $field8->setValue(50);
  70.         $field9->setSize(30050);
  71.         
  72.         // add rows for the fields
  73.         $table->addRowSet( new TLabel('TEntry object:'), $field1 );
  74.         $table->addRowSet( new TLabel('TEntry not editable:'), $field2 );
  75.         $table->addRowSet( new TLabel('TEntry with mask:'), $field3, new TLabel('99.999-999') );
  76.         $table->addRowSet( new TLabel('TEntry with maxlength (10):'), $field4 );
  77.         $table->addRowSet( new TLabel('TPassword object:'), $field5 );
  78.         $table->addRowSet( new TLabel('TDate Object:'), $field6 );
  79.         $table->addRowSet( new TLabel('Spinner Object:'), $field7 );
  80.         $table->addRowSet( new TLabel('Slider Object:'), $field8 );
  81.         $table->addRowSet( new TLabel('TText Object:'), $field9 );
  82.         
  83.         // creates the action button
  84.         $button1=new TButton('action1');
  85.         // define the button action
  86.         $button1->setAction(new TAction(array($this'onSave')), 'Save');
  87.         $button1->setImage('ico_save.png');
  88.         
  89.         // define wich are the form fields
  90.         $this->form->setFields(array($field1$field2$field3$field4$field5,
  91.                                       $field6$field7$field8$field9$button1));
  92.         
  93.         // add a row for the button
  94.         $row=$table->addRow();
  95.         $row->addCell($button1);
  96.         
  97.         // wrap the page content using vertical box
  98.         $vbox = new TVBox;
  99.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  100.         $vbox->add($notebook);
  101.         
  102.         parent::add($vbox);
  103.     }
  104.     
  105.     /**
  106.      * Simulates an save button
  107.      * Show the form content
  108.      */
  109.     public function onSave($param)
  110.     {
  111.         $data $this->form->getData(); // optional parameter: active record class
  112.         
  113.         // put the data back to the form
  114.         $this->form->setData($data);
  115.         
  116.         // creates a string with the form element's values
  117.         $message 'Field 1 : ' $data->field1 '<br>';
  118.         $message.= 'Field 2 : ' $data->field2 '<br>';
  119.         $message.= 'Field 3 : ' $data->field3 '<br>';
  120.         $message.= 'Field 4 : ' $data->field4 '<br>';
  121.         $message.= 'Field 5 : ' $data->field5 '<br>';
  122.         $message.= 'Field 6 : ' $data->field6 '<br>';
  123.         $message.= 'Field 7 : ' $data->field7 '<br>';
  124.         $message.= 'Field 8 : ' $data->field8 '<br>';
  125.         $message.= 'Field 9 : ' $data->field9 '<br>';
  126.         
  127.         // show the message
  128.         new TMessage('info'$message);
  129.     }
  130. }
  131. ?>


Boa Sorte !

Felipe Cortez


FC

Felipe Fica melhor assim não acha?

$field8->setSize(10);//alterado o tamanho do slider
$field8->setRange(0,100,10);// Range
$field8->setDirection('vertical');//acresentado a variavel direction

  1. <?php
  2. Namespace Adianti\Widget\Form;
  3. use Adianti\Widget\Form\AdiantiWidgetInterface;
  4. use Adianti\Widget\Base\TElement;
  5. use Adianti\Widget\Base\TScript;
  6. use Adianti\Widget\Form\TField;
  7. /**
  8.  * Slider Widget
  9.  *
  10.  * @version    2.0
  11.  * @package    widget
  12.  * @subpackage form
  13.  * @author     Pablo Dall'Oglio
  14.  * @copyright  Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  15.  * @license    http://www.adianti.com.br/framework-license
  16.  */
  17. class TSlider extends TField implements AdiantiWidgetInterface
  18. {
  19.     protected $id;
  20.     private $min;
  21.     private $max;
  22.     private $step;
  23.     private $direction;
  24.     
  25.     /**
  26.      * Class Constructor
  27.      * @param $name Name of the widget
  28.      */
  29.     public function __construct($name)
  30.     {
  31.         parent::__construct($name);
  32.         $this->id   'tslider_'.uniqid();
  33.     }
  34.     
  35.     /**
  36.      * Define the field's range
  37.      * @param $min Minimal value
  38.      * @param $max Maximal value
  39.      * @param $step Step value
  40.      */
  41.     public function setRange($min$max$step)
  42.     {
  43.         $this->min $min;
  44.         $this->max $max;
  45.         $this->step $step;
  46.         $this->value $min;
  47.         
  48.         
  49.     }
  50.     
  51.     //rotina para modificar o direction do slider
  52.     public function setDirection($direction)
  53.     {
  54.         $this->direction '"'.$direction.'"';
  55.         
  56.     }
  57.     
  58.     
  59.     
  60.     
  61.     /**
  62.      * Enable the field
  63.      * @param $form_name Form name
  64.      * @param $field Field name
  65.      */
  66.     public static function enableField($form_name$field)
  67.     {
  68.         TScript::create" tslider_enable_field('{$form_name}', '{$field}'); " );
  69.     }
  70.     
  71.     /**
  72.      * Disable the field
  73.      * @param $form_name Form name
  74.      * @param $field Field name
  75.      */
  76.     public static function disableField($form_name$field)
  77.     {
  78.         TScript::create" tslider_disable_field('{$form_name}', '{$field}'); " );
  79.     }
  80.     
  81.     /**
  82.      * Shows the widget at the screen
  83.      */
  84.     public function show()
  85.     {
  86.         // define the tag properties
  87.         $this->tag-> name  $this->name;    // TAG name
  88.         $this->tag-> value $this->value;   // TAG value
  89.         $this->tag-> type  'text';         // input type
  90.         $this->tag-> style "width:{$this->size}px";  // size
  91.         
  92.         if ($this->id)
  93.         {
  94.             $this->tag->{'id'} = $this->id;
  95.         }
  96.         
  97.         // verify if the widget is editable
  98.         if (parent::getEditable())
  99.         {
  100.             $this->tag-> readonly "1";
  101.             $this->tag-> style "width:40px;-moz-user-select:none;border:0;text-align:center";
  102.             
  103.             $div = new TElement('div');
  104.             $div-> id $this->id.'_div';
  105.             $div-> style "width:{$this->size}px";
  106.             
  107.             $main_div = new TElement('div');
  108.             $main_div-> style="text-align:center;width:{$this->size}px";
  109.             
  110.             TScript::create(" tslider_start( '#{$this->id}', {$this->value}{$this->min}{$this->max}{$this->step}{$this->direction} ); ");
  111.             
  112.             $main_div->add($this->tag);
  113.             $main_div->add($div);
  114.             $main_div->show();
  115.         }
  116.         else
  117.         {
  118.             $this->tag-> readonly "1";
  119.             $this->tag->{'class'} = 'tfield_disabled'// CSS
  120.             $this->tag-> style "width:40px;-moz-user-select:none;";
  121.             $this->tag-> onmouseover "style.cursor='default'";
  122.             $this->tag->show();
  123.         }
  124.     }
  125.     
  126.     /**
  127.      * Set the value
  128.      */
  129.     public function setValue($value)
  130.     {
  131.         parent::setValue( (int) $value);
  132.     }
  133. }
  134. ?>
FC

Caro Felipe,

Você ajudou muito, não sabe quanto... Me passa a conta, rsrsrs.
Vou executar suas sugestões e assim que conseguir lhe falo.

Muito obrigado mesmo.

Abs,

Felipe