2011-01-12 13 views
0

フォーム用のjQueryツール(http://flowplayer.org/tools/demos/index.html)バリデータを使用していますが、ドロップダウンとラジオボタンの検証方法が不思議でしたか?ドロップダウンボックス/ラジオボタンの検証?

誰でもそれを実装した経験がありますか?

+0

.html)あなたがこれまでに行ったことは、あなたをより良く助けるためのあなたの結果(コード)を示しています – ifaour

+0

申し訳ありませんが、誤植は、チェックボックスを必要としません...ドロップダウンとラジオボタンで動作する必要があります! –

答えて

0

ドキュメントでは、SELECT要素にrequired = "required"属性を使用することもできますが、それは私にとっても機能しません。 カスタムバリデータ機能を使用することにしました。これはあなたのために働くことを望みます。それはかなり基本的ですが、その柔軟性を高めるためにいくつかの他の考慮事項がありません。

$.tools.validator.fn("select[required=required]", function(input, value) { 
    // If the first item in the list is selected return FALSE 
    return !input[0].options[0].selected; 
}); 
+0

どこに追加すればよいですか? –

1

ただ、そうのようにそれを追加します。[ドキュメント] [(http://flowplayer.org/tools/demos/validator/eventsのチェックボックスを検証するための明確な例があります

<script type="text/javascript"> 
$(document).ready(function(){ 
    // initialize validator and supply the onBeforeValidate event in configuration 

$("#GetAQuote").validator({ 
    position: 'top left', 
    offset: [-5, 25], 
    message: '<div><em/><img src="images/form-error.gif" style="float:right;"/></div>'  
    // em element is the arrow 
}); 

$.tools.validator.fn("select[required=required]", function(input, value) { 
    // If the first item in the list is selected return FALSE 
    return !input[0].options[0].selected; 
}); 


$("#GetAQuote").bind("onFail", function(e, errors) { 

// we are only doing stuff when the form is submitted 
if (e.originalEvent.type == 'submit') { 

    // loop through Error objects and add the border color 
    $.each(errors, function() { 
     var input = this.input; 
     input.css({borderColor: '#e6a200'}).focus(function() { 
      input.css({borderColor: '#75a9cc'}); 
     }); 
    }); 
    } 
    }); 
}); 
</script>