Converts laravel rules to jquery validation rules with given $name

@see Illuminate\Html\FormBuilder
6964
public function laravelToJquery($inputName)
	{
		$jqueryRules = [];

		if(!$this->doesRuleExist($inputName))
		{
			return [];
		}

		$rules = explode('|', $this->getRule($inputName));
		$type = $this->getType($rules);

		foreach ($rules as $key => $value) 
		{
			$jqueryRules = $jqueryRules + $this->convertRule($value, $inputName, $type);
		}
		
		return $jqueryRules;
	}
772949
static function laraform($name = null) {
        $el = new ElementDaterangepickerTwbs($name);
        $el->setWrapClass('js-daterangepicker-twbs');
        $el->putTextTwbs('from')->setAttribute('style','display:none');
        $el->putTextTwbs('to')->setAttribute('style','display:none');
        $el->putStaticTwbs('<div class="col-lg-12"><i class="fa fa-calendar"></i>&nbsp;<span></span> <b class="caret"></b></div>');
        //$el->putStaticTwbs('<i class="fa fa-calendar"></i>&nbsp;<span></span> <b class="caret"></b>');
        return $el;
    }
1130018
public function getRule($name)
    {
        if ($this->hasRule($name)) {
            return $this->rules[$name];
        }

        throw new \InvalidArgumentException(sprintf('No rule with name "%s" could be found', $name));
    }
568329
public function getValidationRules($formName = false)
    {
        if (is_bool($formName))
            $formName = $this->currentFormName;

        if (array_key_exists($formName, $this->validationRules)) {
            return $this->validationRules[$formName];
        }

        return [];
    }
1005932
protected function validate($name, $key = null)
    {
        if (!is_null($key)) {
            return Memory::make('forms-config')->get($key);
        }
        $control = $this->runtime->get('control', []);

        /** before middleware gives information about current middleware action and controller * */
        if (empty($control)) {
            return false;
        }
        $keyname       = $this->getFormConfigKey($name, $control);
        /** we will get this from cache * */
        $configuration = Memory::make('forms-config')->get($keyname);
        /** when we dont find any information about form in current route * */
        if (empty($configuration)) {
            return false;
        }
        /** when current action is not same with action from form configuration * */
        if ((int) $control['action_id'] !== (int) $configuration['action']) {
            return false;
        }
        return $configuration;
    }
23554
public function input($name, $options = array())
    {
        $options += array(
            "type"  => "text",
            "id"    => $this->id($name),
            "name"  => $this->name($name),
            "error" => true,
            "class" => "",
            "value" => "",
            "label" => null
        );

        $currentValue = $this->getCurrentValue($options['name']);

        $errorHtml = "";
        $fieldHasErrors = false;

        if (!is_null($this->associatedEntity)) {
            // Checkboxes may be posted has data[name][0] and therefore
            // we need to remove it to get the absolute field name.
            $validationName = $options["type"] === "checkbox" ?
                preg_replace('/\[\d+\]$/', '', $name) :
                $name;

            if ($this->associatedEntity->hasErrors($validationName)) {
                if ((bool)$options['error']) {
                    $errorHtml = $this->generateInlineErrors($validationName);
                }
                $fieldHasErrors = true;
                $options['class'] .= " error ";
            }
        }
        unset($options["error"]);

        $label = "";
        if (!is_null($options['label'])) {
            $labelOptions = array(
                "for"    => $options["id"],
                "class" => $fieldHasErrors ? "error" : "",
                "label" => $options["label"],
            );

            $label .= $this->label($options['name'], $labelOptions);
        }
        unset($options['label']);

        switch (strtolower($options['type'])) {
            case "textarea":
                return $label . "\n" . $this->generateTextarea($options, $currentValue) . $errorHtml . "\n";
            case "select":
                return $label . "\n" . $this->generateSelect($options, $currentValue) . $errorHtml . "\n";
            case "radio":
                return $this->generateRadio($options, $currentValue) . $errorHtml . "\n" . $label . "\n";
            case "checkbox":
                return $this->generateCheckbox($options, $currentValue) . $errorHtml . "\n" . $label . "\n";
            case "hidden":
                return $label . "\n" . $this->generateHidden($options, $currentValue) . $errorHtml . "\n";
            default:
                return $label . "\n" . $this->generateTextinput($options, $currentValue) . $errorHtml . "\n";
        }
    }
452722
protected function buildClass($name)
    {
        $stub = $this->files->get($this->getStub());

        $viewPath = $this->option('view-path') ? $this->option('view-path') . '.' : '';
        $crudName = strtolower($this->option('crud-name'));
        $crudNameSingular = str_singular($crudName);
        $modelName = $this->option('model-name');
        $modelNamespace = $this->option('model-namespace');
        $routeGroup = ($this->option('route-group')) ? $this->option('route-group') . '/' : '';
        $routePrefix = ($this->option('route-group')) ? $this->option('route-group') : '';
        $routePrefixCap = ucfirst($routePrefix);
        $perPage = intval($this->option('pagination'));
        $viewName = snake_case($this->option('crud-name'), '-');
        $fields = $this->option('fields');
        $validations = rtrim($this->option('validations'), ';');

        $validationRules = '';
        if (trim($validations) != '') {
            $validationRules = "\$this->validate(\$request, [";

            $rules = explode(';', $validations);
            foreach ($rules as $v) {
                if (trim($v) == '') {
                    continue;
                }

                // extract field name and args
                $parts = explode('#', $v);
                $fieldName = trim($parts[0]);
                $rules = trim($parts[1]);
                $validationRules .= "\n\t\t\t'$fieldName' => '$rules',";
            }

            $validationRules = substr($validationRules, 0, -1); // lose the last comma
            $validationRules .= "\n\t\t]);";
        }

        if (\App::VERSION() < '5.3') {
            $snippetUp = <<<EOD
        if (\$request->hasFile('{{fieldName}}')) {
            \$file = \$request->file('{{fieldName}}');
            \$fileName = str_random(40) . '.' . \$file->getClientOriginalExtension();
            \$destinationPath = storage_path('/app/public/uploads');
            \$file->move(\$destinationPath, \$fileName);
            \$requestData['{{fieldName}}'] = 'uploads/' . \$fileName;
        }
EOD;
        } else {
            $snippetCreateOne = <<<EOD
        if (\$request->has('{{fieldName}}')) {
            \${{fieldName}}Name = str_random(40) . '.' . \$request->{{fieldName}}->extension();
            \$requestData['{{fieldName}}'] = \${{fieldName}}Name;
        }
EOD;
            $snippetCreateTwo = <<<EOD
        if (\$request->has('{{fieldName}}')) {
            \$path = '/uploads/{{crudName}}/' . \$store->id . '/';
            Storage::makeDirectory(\$path );
            Image::make(\$request->{{fieldName}})->resize(120, 120, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . \${{fieldName}}Name));
            Image::make(\$request->{{fieldName}})->resize(300, 300, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . 'big' . \${{fieldName}}Name));
        }
EOD;
            $snippetUp = <<<EOD
        if (\$request->has('{{fieldName}}')) {
            \${{fieldName}}Name = str_random(40) . '.' . \$request->{{fieldName}}->extension();
            \$requestData['{{fieldName}}'] = \${{fieldName}}Name;
            \$path = '/uploads/{{crudName}}/' . \$up->id . '/';
            if (!empty(\$up->{{fieldName}})) {
                Storage::delete(\$path . \$up->{{fieldName}});
                Storage::delete(\$path . 'big' . \$up->{{fieldName}});
            }
            Storage::makeDirectory(\$path );
            Image::make(\$request->{{fieldName}})->resize(120, 120, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . \${{fieldName}}Name));
            Image::make(\$request->{{fieldName}})->resize(300, 300, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . 'big' . \${{fieldName}}Name));
        }
EOD;
            $snippetDelPicture = <<<EOD
        if (!empty(\$del->{{fieldName}})) {
            \$path = '/uploads/{{crudName}}/' . \$del->id . '/';
                Storage::deleteDirectory(\$path);
        }
EOD;
        }


        $fieldsArray = explode(';', $fields);
        $fileSnippetCreateOne = '';
        $fileSnippetCreateTwo = '';
        $fileSnippetUp = '';
        $fileSnippetDelPicture = '';
        $whereSnippet = '';

        if ($fields) {
            $x = 0;
            foreach ($fieldsArray as $index => $item) {
                $itemArray = explode('#', $item);

                if (trim($itemArray[1]) == 'file') {
                    $fileSnippetCreateOne .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetCreateOne) . "\n";
                    $fileSnippetCreateTwo .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetCreateTwo) . "\n";
                    $fileSnippetUp .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetUp) . "\n";
                    $fileSnippetDelPicture .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetDelPicture) . "\n";
                }

                $fieldName = trim($itemArray[0]);

                $whereSnippet .= ($index == 0) ? "where('$fieldName', 'LIKE', \"%\$keyword%\")" . "\n                " : "->orWhere('$fieldName', 'LIKE', \"%\$keyword%\")" . "\n                ";
            }

            $whereSnippet .= "->";
        }

        return $this->replaceNamespace($stub, $name)
            ->replaceViewPath($stub, $viewPath)
            ->replaceViewName($stub, $viewName)
            ->replaceCrudName($stub, $crudName)
            ->replaceCrudNameSingular($stub, $crudNameSingular)
            ->replaceModelName($stub, $modelName)
            ->replaceModelNamespace($stub, $modelNamespace)
            ->replaceModelNamespaceSegments($stub, $modelNamespace)
            ->replaceRouteGroup($stub, $routeGroup)
            ->replaceRoutePrefix($stub, $routePrefix)
            ->replaceRoutePrefixCap($stub, $routePrefixCap)
            ->replaceValidationRules($stub, $validationRules)
            ->replacePaginationNumber($stub, $perPage)
            ->replaceFileSnippetCreateOne($stub, $fileSnippetCreateOne)
            ->replaceFileSnippetCreateTwo($stub, $fileSnippetCreateTwo)
            ->replaceFileSnippetUp($stub, $fileSnippetUp)
            ->replaceFileSnippetDelPicture($stub, $fileSnippetDelPicture)
            ->replaceWhereSnippet($stub, $whereSnippet)
            ->replaceClass($stub, $name);
    }
382752
function($target, customRule) {

        var $form = null, _id = null;

        try {
            if ( $target.getAttribute && $target.getAttribute('id') ) {
                _id = $target.getAttribute('id');
                if ( typeof(instance.$forms[_id]) != 'undefined')
                    $form = instance.$forms[_id];
                else
                    throw new Error('form instance `'+ _id +'` not found');

            } else {
                throw new Error('Validator::bindForm($target, customRule): `$target` must be a DOM element\n'+err.stack )
            }
        } catch(err) {
            throw new Error('Validator::bindForm($target, customRule) could not bind form `'+ $target +'`\n'+err.stack )
        }

        if ( typeof($form) != 'undefined' && $form.binded) {
            return false
        }

        var withRules = false, rule = null, evt = '', procced = null;

        if ( typeof(customRule) != 'undefined' || typeof(_id) == 'string' && typeof(instance.rules[_id.replace(/\-/g, '.')]) != 'undefined' ) {
            withRules = true;

            if ( customRule && typeof(customRule) == 'object' ) {
                rule = customRule
            } else if ( customRule && typeof(customRule) == 'string' && typeof(instance.rules[customRule.replace(/\-/g, '.')]) != 'undefined') {
                rule = instance.rules[customRule.replace(/\-/g, '.')]
            } else {
                rule = instance.rules[_id.replace(/\-/g, '.')]
            }

            $form.rules = rule
        }

        // form fields
        if (!$form.defaultFields)
            $form.defaultFields = {};

        // binding form elements
        var type        = null
            , id        = null
            // input: checkbox, radio
            , $inputs   = $target.getElementsByTagName('input')
            // select
            , $select   = $target.getElementsByTagName('select')
        ;

        var elId = null;
        for (var i = 0, len = $inputs.length; i < len; ++i) {
            elId = $inputs[i].getAttribute('id');
            if (!elId) {
                elId = 'input.' + uuid.v1();
                $inputs[i].setAttribute('id', elId)
            }

            if (!$form.defaultFields[ elId ])
                $form.defaultFields[ elId ] = $inputs[i].value;
        }

        var selectedIndex = null, selectedValue = null;
        for (var s = 0, sLen = $select.length; s < sLen; ++s) {
            elId = $select[s].getAttribute('id');
            if (!elId) {
                elId = 'select.' + uuid.v1();
                $select[s].setAttribute('id', elId)
            }

            if ($select[s].options && !$form.defaultFields[ elId ]) {
                selectedIndex = 0;
                selectedValue = $select[s].getAttribute('data-value');

                if ( $select[s].options[ $select[s].selectedIndex ].index ) {
                    selectedIndex = $select[s].options[ $select[s].selectedIndex ].index
                } else if ( typeof(selectedValue) != 'undefined' ) {
                    for (var o = 0, oLen = $select[s].options.length; o < oLen; ++o ) {
                        if ( $select[s].options[o].value == selectedValue) {
                            selectedIndex = o;
                            break
                        }
                    }
                }

                $form.defaultFields[ elId ] = selectedIndex;
                // update select
                $select[s].options[ selectedIndex ].selected = true;
                $select[s].setAttribute('data-value',  $select[s].options[ selectedIndex ].value);

            }
        }

        var updateCheckBox = function($el) {

            var checked     = $el.checked;

            if ( !checked || checked == 'null' || checked == 'false' || checked == '' ) {

                // prevents ticking behavior
                setTimeout(function () {
                    $el.checked = false;
                }, 0);

                $el.removeAttribute('checked');
                $el.value = false;
                $el.setAttribute('value', 'false');

            } else {

                // prevents ticking behavior
                setTimeout(function () {
                    $el.checked = true;
                }, 0);

                $el.setAttribute('checked', 'checked');
                //boolean exception handling
                $el.value = true;
                $el.setAttribute('value', 'true');

            }
        };

        var updateRadio = function($el, isInit) {
            var checked = $el.checked;
            var isBoolean = /^(true|false)$/i.test($el.value);

            // loop if radio group
            if (!isInit) {
                var radioGroup = document.getElementsByName($el.name);
                //console.log('found ', radioGroup.length, radioGroup)
                for (var r = 0, rLen = radioGroup.length; r < rLen; ++r) {
                    if (radioGroup[r].id !== $el.id) {
                        radioGroup[r].checked = false;
                        radioGroup[r].removeAttribute('checked');
                    }
                }
            }

            if ( !checked || checked == 'null' || checked == 'false' || checked == '' ) {

                // prevents ticking behavior
                setTimeout(function () {
                    $el.checked = false;
                }, 0)

                $el.removeAttribute('checked');

                if (isBoolean) {
                    $el.value = false;
                }

            } else {

                // prevents ticking behavior
                setTimeout(function () {
                    $el.checked = true;
                }, 0)

                $el.setAttribute('checked', 'checked');

                if (isBoolean) { // no multiple choice supported
                    $el.value = true;
                }
                var radioGroup = document.getElementsByName($el.name);
                    //console.log('found ', radioGroup.length, radioGroup)
                    for (var r = 0, rLen = radioGroup.length; r < rLen; ++r) {
                        if (radioGroup[r].id !== $el.id) {
                            radioGroup[r].checked = false;
                            radioGroup[r].removeAttribute('checked');
                            if (isBoolean) {
                                radioGroup[r].value = false;
                            }
                        }
                    }


            }
        }

        evt = 'click';

        procced = function () {
            // click proxy
            addListener(gina, $target, 'click', function(event) {

                if ( /(label)/i.test(event.target.tagName) )
                    return false;

                if ( typeof(event.target.id) == 'undefined' || !event.target.getAttribute('id') ) {
                    event.target.setAttribute('id', 'click.' + uuid.v1() );
                    event.target.id = event.target.getAttribute('id')
                } else {
                    event.target.id = event.target.getAttribute('id')
                }


                if (/^click\./.test(event.target.id) || withRules) {

                    var _evt = event.target.id;

                    if (!_evt) return false;

                    if ( ! /^click\./.test(_evt) ) {
                        _evt = event.target.id
                    }

                    // prevent event to be triggered twice
                    if ( typeof(event.defaultPrevented) != 'undefined' && event.defaultPrevented )
                        return false;

                    if (gina.events[_evt]) {
                        cancelEvent(event);

                        triggerEvent(gina, event.target, _evt, event.detail);
                    }

                }

            })
        }


        procced()

        for (var i=0, len = $inputs.length; i<len; ++i) {
            type    = $inputs[i].getAttribute('type');

            if ( typeof($inputs[i].id) == 'undefined' || $inputs[i].id == '' ) {
                $inputs[i]['id'] = type +'-'+ uuid.v1();
                $inputs[i].setAttribute('id', $inputs[i]['id'])
            }


            // recover default state only on value === true || false || on
            if ( typeof(type) != 'undefined' && type == 'checkbox' && /^(true|false|on)$/i.test($inputs[i].value) || typeof(type) != 'undefined' && type == 'checkbox' && !$inputs[i].getAttribute('value') ) {

                if ( !/^(true|false|on)$/i.test($inputs[i].value)  ) {

                    if ( !$inputs[i].checked || $inputs[i].checked == 'null' || $inputs[i].checked == 'false' || $inputs[i].checked == '' ) {
                        $inputs[i].value = false;
                        $inputs[i].setAttribute('value', false)
                    } else {
                        $inputs[i].value = true;
                        $inputs[i].setAttribute('value', true)
                    }
                }


                evt = $inputs[i].id;

                procced = function ($el, evt) {

                    // recover default state only on value === true || false
                    addListener(gina, $el, evt, function(event) {

                        if ( /^(true|false|on)$/i.test(event.target.value) ) {
                            cancelEvent(event);
                            updateCheckBox(event.target);
                        }
                    });

                    // default state recovery
                    var value = $el.value || $el.getAttribute('value') || $el.getAttribute('data-value');
                    if ( /^(true|false|on)$/i.test(value)  ) {

                        if ( typeof(value) != 'undefined' && /^(true|on|false)$/.test(value) ) {
                            $el.checked = /true|on/.test(value) ? true : false;
                        }

                        updateCheckBox($el);
                    }


                }

                if ( typeof(gina.events[evt]) != 'undefined' && gina.events[evt] == $inputs[i].id ) {
                    removeListener(gina, $inputs[i], evt);
                    procced($inputs[i], evt)

                } else {
                    procced($inputs[i], evt)
                }

            } else if ( typeof(type) != 'undefined' && type == 'radio' ) {

                evt = $inputs[i].id;

                procced = function ($el, evt) {
                    addListener(gina, $el, evt, function(event) {

                        cancelEvent(event);
                        updateRadio(event.target);
                    });


                    updateRadio($el, true);
                }

                if ( typeof(gina.events[evt]) != 'undefined' && gina.events[evt] == $inputs[i].id ) {
                    removeListener(gina, $inputs[i], evt);
                    procced(event.target, evt)

                } else {
                    procced($inputs[i], evt)
                }
            }
        }


        if (withRules) {

            evt = 'validate.' + _id;
            procced = function () {

                // attach form event
                addListener(gina, $target, evt, function(event) {
                    cancelEvent(event);


                    var result = event['detail'] || $form.eventData.validation;
                    //console.log('$form[ '+_id+' ] validation done !!!\n isValid ? ', result['isValid'](), '\nErrors -> ', result['errors'], '\nData -> ', result['data']);

                    handleErrorsDisplay(event['target'], result['errors'], result['data']);

                    var _id = event.target.getAttribute('id');

                    if ( result['isValid']() ) { // send if valid
                        // now sending to server
                        // TODO - remove comments, or replace 'submit' by 'submit.' + _id
                        //if ( $form.withUserBindings && /validate\./.test(event.type) && typeof(gina.events[event.type]) != 'undefined' ) {
                        //    triggerEvent(gina, event.target, 'submit', result)
                        //} else {

                            if (instance.$forms[_id]) {
                                instance.$forms[_id].send(result['data']);
                            } else if ($form) { // just in case the form is being destroyed
                                $form.send(result['data']);
                            }
                        //}
                    }

                    return false

                })
            }

            if ( typeof(gina.events[evt]) != 'undefined' && gina.events[evt] == 'validate.' + _id ) {
                removeListener(gina, $form, evt, procced)
            } else {
                procced()
            }



            var proccedToSubmit = function (evt, $submit) {
                // console.log('placing submit ', evt, $submit);
                // attach submit events
                addListener(gina, $submit, evt, function(event) {
                    // start validation
                    cancelEvent(event);

                    // getting fields & values
                    var $fields     = {}
                        , fields    = { '_length': 0 }
                        , id        = $target.getAttribute('id')
                        , rules     = ( typeof(gina.validator.$forms[id]) != 'undefined' ) ? gina.validator.$forms[id].rules : null
                        , name      = null
                        , value     = 0
                        , type      = null
                        , index     = { checkbox: 0, radio: 0 };


                    for (var i = 0, len = $target.length; i<len; ++i) {

                        name    = $target[i].getAttribute('name');

                        if (!name) continue;

                        // TODO - add switch cases against tagName (checkbox/radio)
                        if ( typeof($target[i].type) != 'undefined' && $target[i].type == 'radio' || typeof($target[i].type) != 'undefined' && $target[i].type == 'checkbox' ) {

                            if ( $target[i].checked ) {
                                fields[name] = $target[i].value
                            }  else if ( // force validator to pass `false` if boolean is required explicitly
                            rules
                            && typeof(rules[name]) != 'undefined'
                            && typeof(rules[name].isBoolean)
                            && typeof(rules[name].isRequired)
                            ) {
                                fields[name] = false;
                            }

                        } else {
                            fields[name]    = $target[i].value;
                        }


                        $fields[name]   = $target[i];
                        // reset filed error data attributes
                        $fields[name].setAttribute('data-gina-form-errors', '');

                        ++fields['_length']
                    }

                    //console.log('$fields =>\n' + $fields);

                    //instance.$forms[ $target.getAttribute('id') ].sent = false;

                    if ( fields['_length'] == 0 ) { // nothing to validate
                        delete fields['_length'];
                        var result = {
                            'errors'    : [],
                            'isValid'   : function() { return true },
                            'data'      : formatData(fields)
                        };

                        triggerEvent(gina, $target, 'validate.' + _id, result)

                    } else {
                        // update rule in case the current event is triggered outside the main sequence
                        // e.g.: form `id` attribute rewritten on the fly
                        _id = $target.getAttribute('id');
                        var customRule = $target.getAttribute('data-gina-form-rule');

                        if ( customRule ) { // 'data-gina-form-rule'
                            rule = gina.validator.rules[ customRule.replace(/\-/g, '.') ];
                        } else {
                            rule = gina.validator.$forms[ _id ].rules;
                        }

                        //console.log('testing rule [ '+_id.replace(/\-/g, '.') +' ]\n'+ JSON.stringify(rule, null, 4));
                        //console.log('validating ', $form, fields, rule);
                        validate($target, fields, $fields, rule, function onValidation(result){
                            //console.log('validation result ', 'validate.' + _id, JSON.stringify(result.data, null, 2));
                            //console.log('events ', 'validate.' + _id, self.events )
                            triggerEvent(gina, $target, 'validate.' + _id, result)
                        })
                    }

                });
            }


            // binding submit button
            var $submit = null, $buttons = [], $buttonsTMP = [], buttonId = null;
            $buttonsTMP = $target.getElementsByTagName('button');
            if ( $buttonsTMP.length > 0 ) {
                for(var b = 0, len = $buttonsTMP.length; b < len; ++b) {
                    if ($buttonsTMP[b].type == 'submit')
                        $buttons.push($buttonsTMP[b])
                }
            }

            $buttonsTMP = $target.getElementsByTagName('a');
            if ( $buttonsTMP.length > 0 ) {
                for(var b = 0, len = $buttonsTMP.length; b < len; ++b) {
                    if ( $buttonsTMP[b].attributes.getNamedItem('data-gina-form-submit'))
                        $buttons.push($buttonsTMP[b])
                }
            }


            var onclickAttribute = null, isSubmitType = false;
            for (var b=0, len=$buttons.length; b<len; ++b) {

                $submit = $buttons[b];

                if ($submit.tagName == 'A') { // without this test, XHR callback is ignored
                    //console.log('a#$buttons ', $buttonsTMP[b]);
                    onclickAttribute    = $submit.getAttribute('onclick');
                    isSubmitType        = $submit.getAttribute('data-gina-form-submit');

                    if ( !onclickAttribute && !isSubmitType) {
                        $submit.setAttribute('onclick', 'return false;')
                    } else if ( !/return false/ && !isSubmitType) {
                        if ( /\;$/.test(onclickAttribute) ) {
                            onclickAttribute += 'return false;'
                        } else {
                            onclickAttribute += '; return false;'
                        }
                    }
                }

                if (!$submit['id']) {

                    evt = 'click.'+ uuid.v1();
                    $submit['id'] = evt;
                    $submit.setAttribute( 'id', evt);

                } else {
                    evt = $submit['id'];
                }


                if ( typeof(gina.events[evt]) == 'undefined' || gina.events[evt] != $submit.id ) {
                    proccedToSubmit(evt, $submit)
                }

            }
        }



        evt = 'submit';

        // submit proxy
        addListener(gina, $target, evt, function(e) {

            var $target     = e.target
                , id        = $target.getAttribute('id')
                , isBinded  = instance.$forms[id].binded
            ;

            // prevent event to be triggered twice
            if ( typeof(e.defaultPrevented) != 'undefined' && e.defaultPrevented )
                return false;

            if (withRules || isBinded) {
                cancelEvent(e);
            }


            // just collect data for over forms
            // getting fields & values
            var $fields     = {}
                , fields    = { '_length': 0 }
                , id        = $target.getAttribute('id')
                , rules     = ( typeof(gina.validator.$forms[id]) != 'undefined' ) ? gina.validator.$forms[id].rules : null
                , name      = null
                , value     = 0
                , type      = null
                , index     = { checkbox: 0, radio: 0 };


            for (var i = 0, len = $target.length; i<len; ++i) {
                name = $target[i].getAttribute('name');

                if (!name) continue;

                // checkbox/radio
                if ( typeof($target[i].type) != 'undefined' && $target[i].type == 'radio' || typeof($target[i].type) != 'undefined' && $target[i].type == 'checkbox' ) {

                    if ( $target[i].checked ) {
                        fields[name] = $target[i].value
                    }  else if ( // force validator to pass `false` if boolean is required explicitly
                    rules
                    && typeof(rules[name]) != 'undefined'
                    && typeof(rules[name].isBoolean)
                    && typeof(rules[name].isRequired)
                    ) {
                        fields[name] = false;
                    }

                } else {
                    fields[name]    = $target[i].value;
                }



                $fields[name] = $target[i];
                // reset filed error data attributes
                $fields[name].setAttribute('data-gina-form-errors', '');

                ++fields['_length']
            }


            if ( fields['_length'] == 0 ) { // nothing to validate

                delete fields['_length'];
                var result = {
                    'errors'    : [],
                    'isValid'   : function() { return true },
                    'data'      : formatData(fields)
                };

                if ( typeof(gina.events['submit.' + id]) != 'undefined' ) { // if `on('submit', cb)` is binded
                    triggerEvent(gina, $target, 'submit.' + id, result);
                } else {
                    triggerEvent(gina, $target, 'validate.' + id, result);
                }

            } else {
                // update rule in case the current event is triggered outside the main sequence
                // e.g.: form `id` attribute rewritten on the fly
                //ruleId = id.replace(/-/g, '.');
                //if ( typeof(instance.$forms[id].rules) != 'undefined' )
                //    rule = instance.$forms[id].rules;

                var customRule = $target.getAttribute('data-gina-form-rule');

                if ( customRule ) { // 'data-gina-form-rule'
                    rule = gina.validator.rules[ customRule.replace(/\-/g, '.') ];
                } else {
                    rule = gina.validator.$forms[ id ].rules;
                }

                validate($target, fields, $fields, rule, function onValidation(result){
                    if ( typeof(gina.events['submit.' + id]) != 'undefined' ) { // if `on('submit', cb)` is binded
                        triggerEvent(gina, $target, 'submit.' + id, result);
                    } else {
                        triggerEvent(gina, $target, 'validate.' + id, result);
                    }
                })
            }
        });

        instance.$forms[_id]['binded']  = true;
    }
625397
public function removeValidator($name)
    {
        $returnValue = false;

		$name = (string) $name;
		if(strpos($name, 'tao_helpers_form_validators_') === 0){
			$name = str_replace('tao_helpers_form_validators_', '', $name);
		}
		if(isset($this->validators[$name])){
			unset($this->validators[$name]);
			$returnValue = true;
		}

        return $returnValue;
    }
937857
public function setValidator($name, $element)
    {
        $name = trim($name);
        if ($name === '') {
            throw new InvalidArgumentException('Empty rule name');
        } elseif (is_array($element) && !empty($element['type'])) {
            $element['parent'] = $this;
            $type = $element['type'];
            unset($element['type']);
            $validator = $this->createValidator($type, $element);
        } elseif (true === ($element instanceof \marvin255\serviform\interfaces\Validator)) {
            $element->setParent($this);
            $validator = $element;
        } else {
            throw new InvalidArgumentException('Wrong child type for rule: ' . $name);
        }
        $this->validators[$name] = $validator;

        return $this;
    }
449689
public function runAction($name, $className, $fieldName, $validatorName)
    {
        $this->formName = $name;
        $this->formClassName = $className;
        $this->fieldName = $fieldName;
        $this->validatorName = $validatorName;
        $this->form = $this->getForm();

        $this->formObject = $this->getFormObject();
        $this->formObject->setForm($this->form);

        $this->validation = $this->getFieldValidation();

        $validatorDataObject = new ValidatorDataObject($this->formObject, $this->validation);

        /** @var ValidatorInterface $validator */
        $validator = Core::instantiate(
            $this->validation->getClassName(),
            $this->validation->getOptions(),
            $validatorDataObject
        );

        $fieldValue = ObjectAccess::getProperty($this->form, $this->fieldName);
        $result = $validator->validate($fieldValue);

        $this->result->merge($result);
    }
666501
private function validate(string $name, $value): bool
    {
        if (! isset($this->validators[$name])) {
            return true;
        }

        $errors = [];

        $isValid = true;
        foreach ($this->validators[$name] as $validator) {
            if (! $validator->is_valid($value)) {
                $errors = array_merge($errors, $validator->get_error_messages());
                $isValid = false;
            }
        }

        $element = $this->element($name);
        if ($element instanceof ErrorAwareInterface) {
            $element->withErrors($errors);
        }

        return $isValid;
    }
138679
static function laraform($name = '', $options) {
        $gr = new ElementGroupRadioButtonTwbs();
        $gr->setAttribute('data-toggle', 'buttons');
        foreach ($options as $k => $v) {
            $gr->putRadioTwbs($name, $k)
                ->setAttribute('autocomplete', 'off')
                ->setLabel($v);
        }
        return $gr;
    }
111878
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(isset($_FILES[$key])) {
            if(!\file_exists($_FILES[$key]['tmp_name'])) {
                return 'formvalidator_make_image';
            }
            
            $size = \getimagesize($_FILES[$key]['tmp_name']);
        } else {
            if(!$exists) {
                return false;
            }
            
            $size = @\getimagesizefromstring($value);
        }
        
        if(!$size) {
            return 'formvalidator_make_image';
        }
        
        return true;
    }
1171964
static function laraform($name, $attributes = null, array $data = []) {
        $el = new ElementSelect2Twbs($name);
        $el->addClass('js-larakit-select2 form-control');
        return $el;
    }
271970
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if((!$exists || \is_null($value) || (\is_string($value) === true && \trim($value) === '')) && (!isset($_FILES[$key]) || $_FILES[$key]['error'] != 0)) {
            return 'formvalidator_make_required';
        }
        
        return true;
    }
913433
protected function parserValidationRules($rules, $id = null)
    {

        if($id === null)
        {
            return $rules;
        }

        array_walk($rules, function(&$rules, $field) use ($id)
        {
            if(!is_array($rules))
            {
                $rules = explode("|", $rules);
            }

            foreach($rules as $ruleIdx => $rule)
            {
                // get name and parameters
                @list($name, $params) = array_pad(explode(":", $rule), 2, null);

                // only do someting for the unique rule
                if(strtolower($name) != "unique") {
                    continue; // continue in foreach loop, nothing left to do here
                }

                $p = array_map("trim", explode(",", $params));

                // set field name to rules key ($field) (laravel convention)
                if(!isset($p[1])) {
                    $p[1] = $field;
                }

                // set 3rd parameter to id given to getValidationRules()
                $p[2] = $id;

                $params = implode(",", $p);
                $rules[$ruleIdx] = $name.":".$params;
            }
        });

        return $rules;
    }