Source for file NumberTextInput.class.php
Documentation is available at NumberTextInput.class.php
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
require_once CLASSPATH. "forms/items/HTMLTextInput.class.php";
require_once CLASSPATH. "html/JavaScript.class.php";
* A class to generate text input fields.
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (C) 2003 Daniel Pluecken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* @var char $thousandseperatorchar
* @var char $thousandseperatorchar
* @author Daniel Plücken <daniel@debakel.net>
* @param integer $maxchar
* @param integer $count_of_decimals
* @param string $decimalchar
* @param string $thousandseperatorchar
$thousandseperatorchar = "."
* Stores how many decimal numbers should be shown.
* @author Daniel Plücken <daniel@debakel.net>
* Returns a javascript to probe if the value, that was typed in the
* textfield, is a number.
* @author Daniel Plücken <daniel@debakel.net>
if( empty( $JSTOCHECKNUMBER ) )
$out = "\r\n\r\n<script language=\"javascript\">\r\n";
$out .= " window.checkNumberText = function( which, decimals )\r\n";
$out .= " string = which.value.replace( /(?:[^-0-9". $this
. "0*$|^0*)/g, \"\" );\r\n";
$out .= " string = string.replace( /-+/, \"-\" );\r\n\r\n";
$out .= " string = string.replace( /^(-?)"
. "\"$10$2$3\" );\r\n\r\n";
$tmp = "/(^-)?[^0-9]*(\d*)"
. "[^0-9]*(\d*)[^0-9]*$/";
$out .= " while( !/^-?\d*,?\d*$/.test( string ) )\r\n";
$out .= " string = string.replace( ". $tmp. ", "
. "\"$1$2$3$4\" );\r\n\r\n";
$out .= " string = string.replace( /^". $this
$out .= " if( pattern.test( string ) )\r\n";
$out .= " reppattern = /(-?)(\d|\d\d|\d\d\d)((\d\d\d)+("
$out .= " reppattern = /(-?)(\d|\d\d|\d\d\d)((\d\d\d)+)$/;\r\n";
$out .= " while( reppattern.test( string ) )\r\n";
$out .= " string = string.replace( reppattern, \"$1$2"
$out .= " if( string == \"\" || string == \"-\" )\r\n";
$out .= " string = \"0\";\r\n\r\n";
$out .= " string = string.replace( /,+$/, \"\" );\r\n\r\n";
$out .= " which.value = string;\r\n\r\n";
$out .= " if( decimals == 0 )\r\n";
. "(pos = which.value.indexOf('". $this->decimalchar. "')) != -1 "
$out .= " which.value = which.value.substr( 0, pos );\r\n";
. "- (pos = which.value.indexOf('". $this->decimalchar. "')) "
$out .= " which.value = which.value.substr( "
. "0, pos + decimals + 1 "
$out .= " if ( which.value.indexOf('". $this->decimalchar. "') == -1 "
. "&& decimals > 0 )\r\n";
. "+ str_repeat( '0', decimals );\r\n";
$out .= " if ( which.value.indexOf('". $this->decimalchar. "') != -1 )\r\n";
$out .= " which.value += '0';\r\n";
$out .= " return true;\r\n\r\n";
$out .= "</script>\r\n\r\n\r\n";
* Returns an if-order of a javascript to check whether the value of this
* item has the correct format.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $formName
$out = "checkNumberText( document."
* Returns an if-order of a javascript to check whether this item is NOT
* @author Daniel Plücken <daniel@debakel.net>
$out = "document.". $this->parentform->getName(). "."
. $this->name. ".value == \"0\"";
* Generates the sourcecode to build this object and returns it.
* @author Daniel Plücken <daniel@debakel.net>
$out = "unset( \x24value );\r\n";
$out .= "\x24value = \x24_POST[\"". $this->getName(). "\"]\r\n"
. " .\x24_GET[\"". $this->getName(). "\"];\r\n";
$out .= "\x24input[] = new NumberTextInput(\r\n"
? "if( \x24value === \"\" )\r\n"
. " \x24input[count(\x24input)-1]"
. "->setValue( \"". $tmp. "\" );\r\n\r\n"
* Returns a generated string based on the attributes of this object.
* @author Daniel Plücken <daniel@debakel.net>
# Converting the value to type of double, if it isn't already a double
. "[^0-9]+0+$!", "", $str_tmp
} // END of class NumberTextInput
|