Permitir que el evento continúe

I have a custom date picker jQuery plugin. On form submission, the date picker validates the selected date to check whether it is valid or not. In case it is not, it displays an error message, otherwise it debemos proceed and post the form.

What happens is that in case the user inputs a valid date on the first time, everything works fine. But, in case the user inputs an invalid date, the error message shows up and then when the user fixes the date, it still doesn't post the form. It just sits there.

Here's the part of the code that handles the form submit event:

        var hiddenInput = $('.custom-date-picker-value');
        var form = hiddenInput.closest('form');
        $(form).submit(function (e) {
            selectedMonth = monthSelect.find('option:selected').text();
            selectedYear = yearSelect.find('option:selected').text();
            selectedDay = daySelect.find('option:selected').text();

            if (selectedMonth == '' || selectedDay == '' || selectedYear == '') {
            else {
                var dateValue = selectedMonth + '/' + selectedDay + '/' + selectedYear;
                var dob = new Date(dateValue);
                var modifiedDate = new Date(dob.getFullYear() + 2, dob.getMonth(), dob.getDay());
                if (modifiedDate > new Date()) {
                else {
                    console.log('date is valid');

When the user inputs a valid date, I can see a trace being output to the console saying "date is valid", but for some reason the form does not get submitted.

¿Que esta pasando aqui?

preguntado el 04 de julio de 12 a las 10:07

Are you positive that this is the only submit handler for the form? -

@Esailija: Yes, this is the only one. Note though, that I'm using jQuery.validate library to validate other input fields in the form. But even when all other fields are valid, it still does not post the form. So I strongly doubt that it is an issue with jQuery.validate and the other fields. -

esa biblioteca (jQuery.validate) does add its own submit handler to the form, which is very likely the one that prevents default action for the form somehow because your handler is not the one doing it if the branch "date is valid" is reached -

hmmm... makes sense, so any idea on how to solve this issue? -

I guess you could do a minimal jsfiddle that reproduces it and link to that, so other people can hack at it. And double check from the validate plugin documentation that you are using it correctly. -

1 Respuestas

Trate de

return true 

en este caso,

console.log //returns undefined. 

Also, there's a bug with preventDefault on form submit Events in some browsers, so you might want to change



return false;

Respondido 04 Jul 12, 10:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.