Download the PHP package bllim/laravel-to-jquery-validation without Composer
On this page you can find all versions of the php package bllim/laravel-to-jquery-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bllim/laravel-to-jquery-validation
More information about bllim/laravel-to-jquery-validation
Files in bllim/laravel-to-jquery-validation
Package laravel-to-jquery-validation
Short Description This package makes validation rules defined in laravel work client-side by converting to jquery validation rules. It uses Jquery Validation Plugin. It also allows to use laravel validation messages so you can show same messages for both sides.
License MIT
Informations about the package laravel-to-jquery-validation
This package is no more maintained.
Look Laravalid for same function and more features:
- Laravel 4 and Laravel 5 support
- Multi plugin support
- Extendible
- Remote rules support etc.
Laravel to Jquery Validation
About
This package makes validation rules defined in laravel work client-side by converting to jquery validation rules. It uses Jquery Validation Plugin. It also allows to use laravel validation messages so you can show same messages for both sides.
Feature Overview
- Converts validation rules from laravel to jquery validator
- Works with laravel form builder
- Can be set validation rule from controller
- Can distinguish between numeric input and string input
- Supports user friendly input names
Installation
Require bllim/laravel-to-jquery-validation
in composer.json and run composer update
.
{
"require": {
"laravel/framework": "4.0.*",
...
"bllim/laravel-to-jquery-validation": "*"
}
...
}
Composer will download the package. After the package is downloaded, open app/config/app.php
and add the service provider and alias as below:
Also you need to publish configuration file and assets by running the following Artisan commands.
Usage
Since the package uses Jquery Validation Plugin you should include it in (and include jquery of course) your views. Also for unsupported rules in jquery validator, you should include jquery.validate.laravel.js in your views, too. After assets published, they will be copied to your public folder. The last thing you should do at client side is initializing jquery validator plugin as below:
The package uses laravel Form Builder to make validation rules work for both sides. Therefore you should use Form Builder. While opening form by using Form::open you can give $rules as second parameter:
Also if you don't want to struggle with $rules at view files, you can set it in Controller or route by using Form::setValidation . This sets rules for first Form::open
For rules which is related to input type in laravel (such as max, min), the package looks for other given rules to understand which type is input. If you give integer or numeric as rule with max, min rules, the package assume input is numeric and convert to data-rule-max instead of data-rule-maxlength.
The converter assume input is string by default. File type is not supported yet.
Validation Messages
Converter uses validation messages of laravel (app/lang/en/validation.php) by default for client-side too. If you want to use jquery validation messages, you can set useLaravelMessages, false in config file of package which you copied to your config dir. By default, it is true.
Example
Controller/Route side
View side
Supported validation rules
- Required
- URL
- Integer
- Numeric
- IP
- Same
- Regex
- Alpha
- Alphanum
- Image
- Date
- Min
- Max
- Between
Contribute
You can fork and contribute to development of the package. All pull requests is welcome.
Setting New Convertion Rule
The package, converts rules by using defined methods which is named like _convertRuleRuleName and converts messages by using defined methods which is named like _convertMessageRuleName. You can add new methods to convert current rules and messages. You don't have to add method for converting messages if it is working well without adding. There is getErrorMessage method to handle error messages (which contains just :attribute parameter) by default.
Both rule and message converter method take 3 parameters which are:
$parsedRule: ['name' => '', 'parameters' => []] formatted array which gives name and parameters of the rule,
$attribute: attribute name of the input,
$type: type of the current input. by default it is string, if rules of an input contains numeric or integer, it is set numeric.
Both rule and message converter returns attributes for the current input. For example if you are converting required rule, you should add input tag by returning
You can look at existed methods to understand how it works.
Known issues
- Some rules are not supported for now
TODO
- Test script
- Support unsupported rules
License
Licensed under the MIT License
All versions of laravel-to-jquery-validation with dependencies
illuminate/html Version >=4.2
illuminate/support Version >=4.2
illuminate/validation Version >=4.0