Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 26 |
| TMask | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
156 | |
0.00% |
0 / 26 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| setMask | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| getMask | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| show | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 7 |
|||
| setMaskPlaceHolder | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMaskPlaceHoder | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 4 |
|||
| setUsePlaceHolder | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getUsePlaceHolder | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
|||
| 1 | <?php |
| 2 | /* |
| 3 | * Formdin Framework |
| 4 | * Copyright (C) 2012 Ministério do Planejamento |
| 5 | * Criado por Luís Eugênio Barbosa |
| 6 | * Essa versão é um Fork https://github.com/bjverde/formDin |
| 7 | * |
| 8 | * ---------------------------------------------------------------------------- |
| 9 | * This file is part of Formdin Framework. |
| 10 | * |
| 11 | * Formdin Framework is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public License version 3 |
| 13 | * as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License version 3 |
| 21 | * along with this program; if not, see <http://www.gnu.org/licenses/> |
| 22 | * or write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 23 | * Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | * ---------------------------------------------------------------------------- |
| 25 | * Este arquivo é parte do Framework Formdin. |
| 26 | * |
| 27 | * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou |
| 28 | * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação |
| 29 | * do Software Livre (FSF). |
| 30 | * |
| 31 | * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA |
| 32 | * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou |
| 33 | * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português |
| 34 | * para maiores detalhes. |
| 35 | * |
| 36 | * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título |
| 37 | * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
| 38 | * ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 39 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 40 | */ |
| 41 | |
| 42 | /** |
| 43 | * Classe base para criação de inputs de texto com mascara de edição |
| 44 | * |
| 45 | * Esta classe utiliza o plugin meioMask para o jquery. |
| 46 | * site: http://www.meiocodigo.com/projects/meiomask/#mm_usage |
| 47 | * |
| 48 | * $.mask.options = options : { |
| 49 | * attr: 'alt', // an attr to look for the mask name or the mask itself |
| 50 | * mask: null, // the mask to be used on the input |
| 51 | * type: 'fixed', // the mask of this mask |
| 52 | * maxLength: -1, // the maxLength of the mask |
| 53 | * defaultValue: '', // the default value for this input |
| 54 | * textAlign: true, // to use or not to use textAlign on the input |
| 55 | * selectCharsOnFocus: true, //selects characters on focus of the input |
| 56 | * setSize: false, // sets the input size based on the length of the mask (work with fixed and reverse masks only) |
| 57 | * autoTab: true, // auto focus the next form element |
| 58 | * fixedChars : '[(),.:/ -]', // fixed chars to be used on the masks. |
| 59 | * onInvalid : function(){}, |
| 60 | * onValid : function(){}, |
| 61 | * onOverflow : function(){} |
| 62 | * |
| 63 | }; |
| 64 | */ |
| 65 | class TMask extends TEdit |
| 66 | { |
| 67 | private $mask; |
| 68 | private $usePlaceHolder; |
| 69 | private $maskPlaceHoder; |
| 70 | public function __construct($strName,$strValue=null,$strMask=null,$boolRequired=null, $boolUsePlaceHolder = null ) |
| 71 | { |
| 72 | parent::__construct($strName,$strValue,null,$boolRequired); |
| 73 | $this->setMask($strMask); |
| 74 | $this->setUsePlaceHolder($boolUsePlaceHolder); |
| 75 | } |
| 76 | //------------------------------------------------------------------------------------- |
| 77 | public function setMask($strNewMask=null) |
| 78 | { |
| 79 | $this->mask=(string)$strNewMask; |
| 80 | $len = strlen($this->mask); |
| 81 | parent::setMaxLenght($len); |
| 82 | parent::setSize($len+2); |
| 83 | } |
| 84 | //------------------------------------------------------------------------------------- |
| 85 | public function getMask() |
| 86 | { |
| 87 | return $this->mask; |
| 88 | } |
| 89 | //------------------------------------------------------------------------------------- |
| 90 | public function show($print=true) |
| 91 | { |
| 92 | if( (string) $this->getMask()!='') |
| 93 | { |
| 94 | // http://www.meiocodigo.com/projects/meiomask/ |
| 95 | // http://digitalbush.com/projects/masked-input-plugin/ ( com placehoder) |
| 96 | $len = strlen($this->getMask()); |
| 97 | $js = new TElement('script'); |
| 98 | $js->setProperty('type',"text/javascript"); |
| 99 | $js->add('jQuery("#'.$this->getId().'").setMask("'.$this->getMask().'");'); |
| 100 | $this->add($js); |
| 101 | } |
| 102 | return parent::show($print); |
| 103 | } |
| 104 | |
| 105 | public function setMaskPlaceHolder($strChar=null) |
| 106 | { |
| 107 | $this->maskPlaceHolder = $strChar; |
| 108 | } |
| 109 | |
| 110 | function getMaskPlaceHoder() |
| 111 | { |
| 112 | $strChar = is_null( $this->maskPlaceHoder) ? '_' : substr($this->maskPlaceHoder,0,1); |
| 113 | if( strlen($strChar ) < 1 ) |
| 114 | { |
| 115 | $strChar='_'; |
| 116 | } |
| 117 | return $strChar; |
| 118 | } |
| 119 | |
| 120 | function setUsePlaceHolder($boolNewValue=null) |
| 121 | { |
| 122 | $this->usePlaceHolder = $boolNewValue; |
| 123 | } |
| 124 | function getUsePlaceHolder() |
| 125 | { |
| 126 | return ( $this->usePlaceHolder === false ? false : true ); |
| 127 | } |
| 128 | } |
| 129 | /* |
| 130 | $campo = new TMask('teste','123456789','9.9.9.9.9.9.9.9.9',true); |
| 131 | $campo->show(); |
| 132 | */ |
| 133 | /* |
| 134 | $cpf = new TCpfField('num_cpf','CPF:',true); |
| 135 | $cpf->show(); |
| 136 | $cnpj = new TCnpjField('num_cnpj','CNPJ:',true); |
| 137 | $cnpj->show(); |
| 138 | */ |
| 139 | ?> |