在验证引擎中使用datepicker

时间:2018-07-09 15:59:34

标签: validation datepicker jquery-validation-engine

我有一个使用验证引擎的表单,但是使用jquery datepicker的输入元素将不会显示错误消息,甚至不会验证为必需项。有办法使两者同时起作用吗?如果没有,还有其他解决方法吗?

    <input class="validate[required] datepicker" name="dt1" value="日付を選択" data-validation-engine="validate[required]" class="validate[required]"/>

<script>
    //validate engine
    $(document).ready(function(){
        $("#form1").validationEngine('attach', {promptPosition : "topLeft", scroll: false});
       });

    //datepicker
    $('.datepicker').datepicker({
    constrainInput: true,
    closeText: "閉じる",
    prevText: "&#x3C;前",
    nextText: "次&#x3E;",
    currentText: "今日",
    monthNames: [ "1月","2月","3月","4月","5月","6月",
    "7月","8月","9月","10月","11月","12月" ],
    monthNamesShort: [ "1月","2月","3月","4月","5月","6月",
    "7月","8月","9月","10月","11月","12月" ],
    dayNames: [ "日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日" ],
    dayNamesShort: [ "日","月","火","水","木","金","土" ],
    dayNamesMin: [ "日","月","火","水","木","金","土" ],
    weekHeader: "週",
    dateFormat: "yy/mm/dd",
    firstDay: 0,
    isRTL: false,
    showMonthAfterYear: true,
    yearSuffix: "年"
    });
</script>

1 个答案:

答案 0 :(得分:0)

我将字段的data属性指定为“日期”,因此它确实可以正常工作。

                <input class="validate[required,custom[date] datepicker" name="dt1" autocomplete="off" placeholder="日付を選択" data-validation-engine="validate[required,custom[date]" />