0

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

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

4

2 に答える 2

1

そのように追加するだけです:

<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>
于 2012-07-19T16:11:34.527 に答える
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;
});
于 2011-01-13T18:52:16.167 に答える