5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

validation engineの小技まとめ

Last updated at Posted at 2015-12-23

jQuery Validation Engineの小技備忘録です
https://github.com/posabsolute/jQuery-Validation-Engine

#エラーを1つだけ表示する

$('form').validationEngine({ maxErrorsPerField: 1 });

#分割された入力フィールドのエラーを一つにまとめる
電話番号などで[ ]-[ ]-[ ]と分割されている場合

<input type="text" name="tel1" class="validate[required]">
<input type="text" name="tel2" class="validate[required]">
<input type="text" name="tel3" class="validate[required]">

とすると、すべての入力欄にメッセージが出るので一つにまとめたい

<input type="text" name="tel1" id="tel1" class="validate[required]">
<input type="text" name="tel2" id="tel2" class="validate[condRequired[tel01]]">
<input type="text" name="tel3" id="tel3" class="validate[condRequired[tel02]]">

condRequired[tel01]でtel01が入力されていたら必須になるので
前から順番に1つだけメッセージが表示される。

#エラーが出たフォームにクラスを付けたい
addFailureCssClassToField:"クラス名"を指定する

$("#form").validationEngine({addFailureCssClassToField: "inputError"});
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?