<?php

/**
* A MIOLO Field ( control ) to Administer integer values
* It adds a js the permits only nunbers to be digited
* and add the miolo MIntegerValidator
*/
class GnutecaIntegerField extends MTextField
{
    /**
    * Create the GnutecaIntegerField
    *
    * @param $name          the id of the field
    * @param $value         the value of the field
    * @param $label         the label of the field
    * @param $size          the size of the field
    * @param $hint          the hint of the field
    * @param $validator     the default validator
    * @param $isReadOnly    if the field is read only or not
    * @param $required      if the field is required or not
    */
    public function GnutecaIntegerField($name , $value = '', $label = '', $size = 10, $hint = '', $validator = NULL, $isReadOnly = false, $required = false)
    {
        parent::__construct($name, $value, $label, $size, $hint, $validator, $isReadOnly);
        $validator = new MIntegerValidator($name, $label, 'optional');
        $this->addAttribute('onkeypress', 'return OnlyNumbers2(event)');
        if ($required)
        {
            $requiredValidator = new MRequiredValidator($name, $label);
            $this->setValidator($requiredValidator);
        }
        $MIOLO  = MIOLO::getInstance();
        $module = $MIOLO->getCurrentModule();
        $this->page->addScript('GnutecaIntegerField.js', $module);
    }
}
?>
