1

I am trying to validate this select / drop down. I am not getting an error, but the validation is not ocurring. I am using the validation for other fields, which is working fine. Here is my jquery and the select which doesnt want to seem to validate:

$().ready(function() {
$("#cancelForm").validate({
    debug: false,
    errorClass: "authError",     
    errorElement: "span", 
    rules: {
        inputString: "required",
        notes: "required",
        end_time: {required: true}
    },
    messages: {
        inputString: "Please enter the membername",
        notes: "Please enter the notes",
        end_time: "Please select a time"
    }
});
});

Here is my select:

<div class="styled-select">
<select name="end_time" id="end_time">
<option value="">None</option> 
<option value="05:00:00">5:00AM</option>
<option value="05:30:00">5:30AM</option>
</select>
</div>

Thanks in advance for taking a look at my issue.

Matthew Colley
  • 10,816
  • 9
  • 43
  • 63

2 Answers2

0

Instead of end_time: {required: true}, write this:

end_time: {custom_required: true}

And add this custom validation method:

$.validator.addMethod("custom_required", function(value, element) {
    return (value) ? true: false;
}, "Please select the end time.");
spirit walker
  • 304
  • 1
  • 6
-1

I don't think you can use required: true on a select. Because there is always something selected, even if the value is empty.

Maybe try minlength:1

Richard
  • 4,341
  • 5
  • 35
  • 55