HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/ilysium.komma.pro/wwwroot/lib/form/form_live_validation.class.php
<?php
/**
 * Created by Komma.pro
 * User: mikevandersanden
 * Date: 11/1/14
 */

class Form_Live_Validation
{
    /*
     * Javascript output
     */
    private $_js;

    /*
     * Name of the field
     */
    private $_name;

    /*
     * Type of the field
     */
    private $_type;

    /*
     * Milliseconds to wait for validation
     */
    private $_wait = 200;


    /*
     * Constructor
     */
    public function __construct($fieldName, $type)
    {
        // Set name
        $this->_name = $fieldName;
        $this->_type = $type;

        // Start js output
        $this->_js = 'var validate' . ucFirst($this->_name) . ' = new LiveValidation( \'' . $this->_name . '\', { validMessage: \' \', wait: ' . $this->_wait. ' } );';
    }

    /*
     * Initialise: Check what validation to add
     */
    public function init($data)
    {
        foreach($data as $validation)
        {
            // Call method if exists
            if(method_exists($this,'add' . ucfirst($validation)))
            {
                $this->{'add' . ucfirst($validation)}();
            }
        }
    }

    /*
     * Get js output
     */
    public function get()
    {
        return $this->_js;
    }

    /*
     * Add validation for required text fields
     */
    public function addRequired()
    {
        switch($this->_type)
        {
            case 'Field_Type_Select':
                $this->_js .= 'validate' . ucFirst($this->_name) . '.add( Validate.Exclusion, { within: [ \'empty\' ], partialMatch: true, failureMessage: \' \' } );';
                break;
            default:
                $this->_js .= 'validate' . ucFirst($this->_name) . '.add( Validate.Presence, { failureMessage: \' \' } );';
        }
    }

    /*
     * Add validation for price format
     */
    public function addPrice()
    {
        $this->_js .= 'validate' . ucFirst($this->_name) . '.add( Validate.Format, { pattern: /^\d+([.,]\d{2}|)$/ , failureMessage: \' \' } );';
    }

}