YiiWheels
  • Package
  • Class
  • Tree

Packages

  • None
  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • fileupload
      • fileuploader
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhMaskInput
 1 <?php
 2 /**
 3  * WhMaskMoney widget class
 4  *
 5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 6  * @copyright Copyright &copy; 2amigos.us 2013-
 7  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 8  * @package YiiWheels.widgets.maskInput
 9  * @uses YiiStrap.helpers.TbHtml
10  */
11 
12 Yii::import('bootstrap.helpers.TbArray');
13 
14 class WhMaskInput extends CInputWidget
15 {
16 
17     /**
18      * @var array the plugin options
19      * @see http://igorescobar.github.io/jQuery-Mask-Plugin/
20      */
21     public $pluginOptions;
22 
23     /**
24      * @var string
25      */
26     public $mask = '';
27 
28     /**
29      * Initializes the widget.
30      */
31     public function init()
32     {
33         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
34     }
35 
36     /**
37      * Runs the widget.
38      */
39     public function run()
40     {
41         $this->renderField();
42         $this->registerClientScript();
43     }
44 
45     /**
46      * Renders the input field
47      */
48     public function renderField()
49     {
50         list($name, $id) = $this->resolveNameID();
51 
52         TbArray::defaultValue('id', $id, $this->htmlOptions);
53         TbArray::defaultValue('name', $name, $this->htmlOptions);
54 
55         if ($this->hasModel()) {
56             echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
57         } else {
58             echo CHtml::textField($this->name, $this->value, $this->htmlOptions);
59         }
60     }
61 
62     /**
63      * Registers required client script for jquery mask plugin. It doesn't use bootstrap->registerPlugin.
64      */
65     public function registerClientScript()
66     {
67         /* publish assets dir */
68         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
69         $assetsUrl = $this->getAssetsUrl($path);
70 
71         /* @var $cs CClientScript */
72         $cs = Yii::app()->getClientScript();
73 
74         $cs->registerScriptFile($assetsUrl . '/js/jquery.mask.js');
75 
76         /* initialize plugin */
77         $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
78 
79         $options = !empty($this->pluginOptions) ? CJavaScript::encode($this->pluginOptions) : '{}';
80         $script = "jQuery('{$selector}').mask('{$this->mask}',{$options});";
81         Yii::app()->clientScript->registerScript((uniqid(__CLASS__ . '#', true)), $script, CClientScript::POS_END);
82     }
83 }
YiiWheels API documentation generated by ApiGen 2.8.0