DateTime Previous/Next Buttons

DateTime Previous/Next Buttons

jeremydb85jeremydb85 Posts: 4Questions: 0Answers: 0

I'm using a DataTables DateTime control in a form on my site. Everything works great except the Previous & Next month buttons trigger a form submit since their button type attribute isn't set to "button". So they behave like type="submit" buttons.

I've found a couple workarounds, such as checking in the submit event handler for my form, and calling preventDefault / returning false. However, I think it would make more sense for those buttons to simply be defined as "button" type. I realize this is probably a lower priority request but I wanted to get it out there in case anyone else has experienced a similar issue.


  • tangerinetangerine Posts: 3,303Questions: 33Answers: 393

    The example in the docs is working correctly.
    What do you have that's different?

  • jeremydb85jeremydb85 Posts: 4Questions: 0Answers: 0

    There is one form element on that page, but the DateTime instance isn't inside of it. In my case, the DateTime instance is part of a form that gets submitted with a submit button, to save various fields, including one text date field that the DateTime instance is used with. The Previous/Next buttons inside the DateTime instance are causing a form submit since their type isn't defined.

  • jeremydb85jeremydb85 Posts: 4Questions: 0Answers: 0

    Here is an example of what I'm experiencing:,js,output

    I should have mentioned that I'm using the attachTo: 'input' option. Another workaround I found was to not use that option -- as the DateTime popup is then created outside of the form (appended to the body). Then the Previous/Next buttons no longer trigger a submit. You can check the example above with and without the attachTo: 'input' option. With the way my page is structured, I would prefer to keep the DateTime attached to the input.

    This really isn't a huge deal, as there are workarounds, as I've mentioned. I just don't see any reason not to add type="button" to the Previous/Next buttons. It would remedy any possibility of this issue occurring again and would have no negative effects that I can think of.

  • allanallan Posts: 58,882Questions: 1Answers: 9,474 Site admin


    That's awesome - thanks for the suggestion and letting me know about that error. I've committed the fix now and it will be in the next release of DateTime.


  • jeremydb85jeremydb85 Posts: 4Questions: 0Answers: 0

    Thank you, Allan! I really appreciate all the hard work you guys do!

Sign In or Register to comment.