PhpExt : Form [ class tree ] [ index ] [ all elements ]

Source for file NumberField.php

Documentation is available at NumberField.php

  1. <?php
  2. /**
  3.  * PHP-Ext Library
  4.  * http://php-ext.googlecode.com
  5.  * @author Sergei Walter <sergeiw[at]gmail[dot]com>
  6.  * @copyright 2008 Sergei Walter
  7.  * @license http://www.gnu.org/licenses/lgpl.html
  8.  * @link http://php-ext.googlecode.com
  9.  * 
  10.  *  Reference for Ext JS: http://extjs.com
  11.  * 
  12.  */
  13.  
  14. /**
  15.  * @see PhpExt_Form_TextField
  16.  */
  17. include_once 'PhpExt/Form/TextField.php';
  18.  
  19. /**
  20.  * Numeric text field that provides automatic keystroke filtering and numeric validation.
  21.  * 
  22.  * @package PhpExt
  23.  * @subpackage Form
  24.  */
  25. {    
  26.     // AllowDecimals
  27.     /**
  28.      * False to disallow decimal values (defaults to true)
  29.      * @param boolean $value 
  30.      * @return PhpExt_Form_NumberField 
  31.      */
  32.     public function setAllowDecimals($value{
  33.         $this->setExtConfigProperty("allowDecimals"$value);
  34.         return $this;
  35.     }    
  36.     /**
  37.      * False to disallow decimal values (defaults to true)
  38.      * @return boolean 
  39.      */
  40.     public function getAllowDecimals({
  41.         return $this->getExtConfigProperty("allowDecimals");
  42.     }
  43.     
  44.     // AllowNegative
  45.     /**
  46.      * False to prevent entering a negative sign (defaults to true)
  47.      * @param boolean $value 
  48.      * @return PhpExt_Form_NumberField 
  49.      */
  50.     public function setAllowNegative($value{
  51.         $this->setExtConfigProperty("allowNegative"$value);
  52.         return $this;
  53.     }    
  54.     /**
  55.      * False to prevent entering a negative sign (defaults to true)
  56.      * @return boolean 
  57.      */
  58.     public function getAllowNegative({
  59.         return $this->getExtConfigProperty("allowNegative");
  60.     }
  61.     
  62.     // BaseChars
  63.     /**
  64.      * The base set of characters to evaluate as valid numbers (defaults to '0123456789').
  65.      * @param string $value 
  66.      * @return PhpExt_Form_NumberField 
  67.      */
  68.     public function setBaseChars($value{
  69.         $this->setExtConfigProperty("baseChars"$value);
  70.         return $this;
  71.     }    
  72.     /**
  73.      * The base set of characters to evaluate as valid numbers (defaults to '0123456789').
  74.      * @return string 
  75.      */
  76.     public function getBaseChars({
  77.         return $this->getExtConfigProperty("baseChars");
  78.     }
  79.     
  80.     // DecimalPrecision
  81.     /**
  82.      * The maximum precision to display after the decimal separator (defaults to 2)
  83.      * @param integer $value 
  84.      * @return PhpExt_Form_NumberField 
  85.      */
  86.     public function setDecimalPrecision($value{
  87.         $this->setExtConfigProperty("decimalPrecision"$value);
  88.         return $this;
  89.     }    
  90.     /**
  91.      * The maximum precision to display after the decimal separator (defaults to 2)
  92.      * @return integer 
  93.      */
  94.     public function getDecimalPrecision({
  95.         return $this->getExtConfigProperty("decimalPrecision");
  96.     }
  97.     
  98.     // DecimalSeparator
  99.     /**
  100.      * Character(s) to allow as the decimal separator (defaults to '.')
  101.      * @param string $value 
  102.      * @return PhpExt_Form_NumberField 
  103.      */
  104.     public function setDecimalSeparator($value{
  105.         $this->setExtConfigProperty("decimalSeparator"$value);
  106.         return $this;
  107.     }    
  108.     /**
  109.      * Character(s) to allow as the decimal separator (defaults to '.')
  110.      * @return string 
  111.      */
  112.     public function getDecimalSeparator({
  113.         return $this->getExtConfigProperty("decimalSeparator");
  114.     }
  115.     
  116.     // FieldCssClass
  117.     /**
  118.      * The default CSS class for the field (defaults to "x-form-field x-form-num-field")
  119.      * @param string $value 
  120.      * @return PhpExt_Form_NumberField 
  121.      */
  122.     public function setFieldCssClass($value{
  123.         $this->setExtConfigProperty("fieldClass"$value);
  124.         return $this;
  125.     }    
  126.     /**
  127.      * The default CSS class for the field (defaults to "x-form-field x-form-num-field")
  128.      * @return string 
  129.      */
  130.     public function getFieldCssClass({
  131.         return $this->getExtConfigProperty("fieldClass");
  132.     }
  133.     
  134.     // MaxText
  135.     /**
  136.      * Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
  137.      * @param string $value 
  138.      * @return PhpExt_Form_NumberField 
  139.      */
  140.     public function setMaxText($value{
  141.         $this->setExtConfigProperty("maxText"$value);
  142.         return $this;
  143.     }    
  144.     /**
  145.      * Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
  146.      * @return string 
  147.      */
  148.     public function getMaxText({
  149.         return $this->getExtConfigProperty("maxText");
  150.     }
  151.     
  152.     // MaxValue
  153.     /**
  154.      * The maximum allowed value (defaults to Number.MAX_VALUE)
  155.      * @param integer|float$value 
  156.      * @return PhpExt_Form_NumberField 
  157.      */
  158.     public function setMaxValue($value{
  159.         $this->setExtConfigProperty("maxValue"$value);
  160.         return $this;
  161.     }    
  162.     /**
  163.      * The maximum allowed value (defaults to Number.MAX_VALUE)
  164.      * @return integer|float
  165.      */
  166.     public function getMaxValue({
  167.         return $this->getExtConfigProperty("maxValue");
  168.     }
  169.     
  170.     // MinText
  171.     /**
  172.      * Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
  173.      * @param string $value 
  174.      * @return PhpExt_Form_NumberField 
  175.      */
  176.     public function setMinText($value{
  177.         $this->setExtConfigProperty("minText"$value);
  178.         return $this;
  179.     }    
  180.     /**
  181.      * Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
  182.      * @return string 
  183.      */
  184.     public function getMinText({
  185.         return $this->getExtConfigProperty("minText");
  186.     }
  187.     
  188.     // MinValue
  189.     /**
  190.      * The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
  191.      * @param integer|float$value 
  192.      * @return PhpExt_Form_NumberField 
  193.      */
  194.     public function setMinValue($value{
  195.         $this->setExtConfigProperty("minValue"$value);
  196.         return $this;
  197.     }    
  198.     /**
  199.      * The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
  200.      * @return integer|float
  201.      */
  202.     public function getMinValue({
  203.         return $this->getExtConfigProperty("minValue");
  204.     }
  205.     
  206.     // NanText
  207.     /**
  208.      * Error text to display if the value is not a valid number. For example, this can happen if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
  209.      * @param string $value 
  210.      * @return PhpExt_Form_NumberField 
  211.      */
  212.     public function setNanText($value{
  213.         $this->setExtConfigProperty("nanText"$value);
  214.         return $this;
  215.     }    
  216.     /**
  217.      * Error text to display if the value is not a valid number. For example, this can happen if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
  218.      * @return string 
  219.      */
  220.     public function getNanText({
  221.         return $this->getExtConfigProperty("nanText");
  222.     }
  223.     
  224.     public function __construct({
  225.         parent::__construct();
  226.         $this->setExtClassInfo("Ext.form.NumberField","numberfield");
  227.         
  228.         $validProps array(
  229.             "allowDecimals",
  230.             "allowNegative",
  231.             "baseChars",
  232.             "decimalPrecision",
  233.             "decimalSeparator",
  234.             "fieldClass",
  235.             "maxText",
  236.             "maxValue",
  237.             "minText",
  238.             "minValue",
  239.             "nanText"
  240.         );
  241.         $this->addValidConfigProperties($validProps);
  242.     }     
  243.     
  244.     /**
  245.      * Helper function to create an NumberField.  Useful for quick adding it to a ComponentCollection
  246.      *
  247.      * @param string $name The field's HTML name attribute.
  248.      * @param string $label The label text to display next to this field (defaults to '')
  249.      * @param string $id The unique id of this component (defaults to an auto-assigned id).
  250.      * @return PhpExt_Form_NumberField 
  251.      */
  252.     public static function createNumberField($name$label null$id null{
  253.         $c new PhpExt_Form_NumberField();
  254.         $c->setName($name);
  255.         if ($label !== null)
  256.           $c->setFieldLabel($label);
  257.         if ($id !== null)
  258.           $c->setId($id);
  259.         return $c;
  260.     }
  261.  
  262.     
  263. }

Documentation generated on Fri, 08 Aug 2008 15:57:14 -0500 by phpDocumentor 1.4.0