Skip to content

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

Notifications You must be signed in to change notification settings

H-Gh/yii-jquery-form-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

Yii-jQuery-form-validation

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

Usage

php

<div class="form-group field-model-model_attribute_1">
  <?php
    // the format of id name should be like this modelName-attributeName. eg : model is book, attribute of model is name => 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"
    ]);
  ?>
  <div class="help-block"></div>
</div>

jQuery

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

methods

add

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

Rules

Rules can be a single object or array of objects.
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
rule : function(value) {
  //...
}

Example

var $form = $('#form');
$form.yiiValidator('add', {
        model: "model",
        attribute: "model_attribute_1",
        rules: [{
            rule: "required",
            errorMessage: "should fill"
        }]
    });
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!",
            }
        ]
    });

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published