Azureはじめました

Windows Azureで業務システムを組んでみる日記

jquery.validate.unobtrusiveでタブなどに隠れたフィールドの評価がされない

なんてこった。

In the new version of jQuery validation plugin 1.9 by default validation of hidden fields ignored. I'm using CKEditor for textarea input field and it hides the field and replace it with iframe. The field is there, but validation disabled for hidden fields. With validation plugin version 1.8.1 everything works as expected.

jQuery Validate - Enable validation for hidden fields - Stack Overflow

どうやらValidatorのIgnoreで無視されてるようだ。

This worked for me, within an ASP.NET MVC3 site where I'd left the framework to setup unobtrusive validation etc., in case it's useful to anyone:

$("form").data("validator").settings.ignore = "";
jQuery Validate - Enable validation for hidden fields - Stack Overflow

$("form").data("validator")に設定が入ってるのかと確認してみると

f:id:twisted0517:20150313195338p:plain

ignore=":hidden"

('A`) アカン

現状に合わせて修正

  • input type="hidden"はチェックしなくていい。
  • TabやAccordionで隠れてるフィールドはチェックが必要

となると

$("form").data("validator").settings.ignore="input[type='hidden']";

か。

しかし

MVCだとbootstrapを標準で使う割にこの設定は罠やろ。