Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/h-gh/yii-jquery-form-validation

This plugin runs custom validations on custom fileds which are not in Yii model.
https://github.com/h-gh/yii-jquery-form-validation

jquery yii-model yii2 yii2-asset yii2-framework

Last synced: about 2 months ago
JSON representation

This plugin runs custom validations on custom fileds which are not in Yii model.

Awesome Lists containing this project

README

        

# Yii-jQuery-form-validation
This plugin runs custom validations on custom fileds which are not in Yii model.

Usage


php

```php


book-name
echo Html::label("Label", "model-model_attribute_1"); ?>
echo Html::textInput("Model[model_attribute_1]", null, [
"class" => "form-control",
"id" => "model-model_attribute_1"
]);
?>


```

jQuery

```javascript
var $form = $('#form');
$form.yiiValidator('add', {
model: "model",
attribute: "model_attribute_1",
rules: // ...
});
```

methods


add

```javascript
var $form = $('#form');
$form.yiiValidator('add', {
//...
});
```

Rules


Rules can be a single object or array of objects.

```javascript
rules : {
//...
}
rules : [
{
//...
},
{
//...
}
];
```

Each rule consists of two element :
```
rule
errorMessage
```

Rule can be selected from below list or be a function.
```
required
number
email
url
```

```javascript
rule : function(value) {
//...
}
```

Example

```javascript
var $form = $('#form');
$form.yiiValidator('add', {
model: "model",
attribute: "model_attribute_1",
rules: [{
rule: "required",
errorMessage: "should fill"
}]
});
```

```javascript
var $form = $('#form');
$form.yiiValidator('add', {
model: "model",
attribute: "model_attribute_2",
rules: [
{rule : "required", errorMessage : "should fill"},
{
rule: function (value) {
return value > 0 && value !== "";
},
errorMessage: "should more than zero!",
}
]
});
```