matheen ulla
matheen ulla

Reputation: 558

jquery validation plugin with jquery datepicker error(Please enter a valid date)

I'm using a jquery validation plugin for form validation. I'm validating the date. But I'm getting the error like

please enter the valid date

if I change the Jquery datepicker format. I don't know where it is coming from.

I'm using jquery ui date picker.

 $('.date').datepicker({
        dateFormat: "dd-mm-yy",
        changeMonth:true,
        changeYear:true
 });

form

<form method="post" id="policiesform" action="{{ url('createpoli') }}" enctype="multipart/form-data">
 <div class="col-lg-4 col-md-6 col-sm-12">
      <div class="form-group">
      <div class="row text-center">
      <div class="col-lg-4 col-md-6 col-sm-6">
      Start Date

      </div>
      <div class="col-lg-8 col-md-6 col-sm-6">
      <input type="text"  placeholder="Start Date" class="form-control date" name="startdte" readonly>

      </div>
      </div>

        </div>

      </div>
      <div class="col-lg-4 col-md-6 col-sm-12">
      <div class="form-group">
      <div class="row text-center">
      <div class="col-lg-4 col-md-6 col-sm-6">
         End Date
      </div>
      <div class="col-lg-8 col-md-6 col-sm-6">
      <input  placeholder="End Date" class="form-control date" name="enddte" readonly>
      </div>
      </div>

        </div> 
   </div>
</form>

validation

$('#policiesform').validate({
        rules: {
            startdte: {
                required:true,
            },
            enddte: {
                required:true,
            },


        },
        messages: {
            startdte: {
                required:"Start Date is Required",

            },
            enddte: {
                required:"End Date is Required",

            },  

        }
    });

Upvotes: 1

Views: 1873

Answers (2)

matheen ulla
matheen ulla

Reputation: 558

if you have downloaded the jquery validation plugin then you have to make changes in
jquery.validate.min.js, for more information you can find here Where trigger the "Please enter a valid date." in jquery.validate.js

Upvotes: 1

jvk
jvk

Reputation: 2201

try start-date, end-date id's instead of class

Start Date

$('#start-date').datepicker({
        dateFormat: "dd-mm-yy",
        changeMonth:true,
        changeYear:true
 }).on('change', function() {
        $(this).valid();  // triggers the validation test
        // '$(this)' refers to '$(".date")'
 });

End Date

$('#end-date').datepicker({
            dateFormat: "dd-mm-yy",
            changeMonth:true,
            changeYear:true
     }).on('change', function() {
            $(this).valid();  // triggers the validation test
            // '$(this)' refers to '$(".date")'
     });

Upvotes: 0

Related Questions