2

I have a datepicker, and I need to be able to enter a date manually in multiple different formats. For example, for May 7, 2015, I need to be able to enter:

05/07/2015 05072015 050715 5715

I understand how to format all these above based off of the the jquery docs, but I cannot figure out how to make the input box take multiple different dates. I can change the format to any one of these individually, which will allow me to type in that specific format, but I can only do this once by defining the "dateFormat".

I found another page where the same problem seems to have been answered, but after many attempts, I cannot figure out how to fit it into my code successfully, here is the link to this page:

Datepicker and allowing multiple input formats

How do I fit that solution into the following code:

<h3>Date Selection</h3>
<label for="from">From</label>
<input type="text" id="from" name="from" />
<input type="text" id="altdate" />
<label for="to">to</label>
<input type="text" id="to" name="to" />
<script>
    $(function() {
        $( "#from" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 2,
            onClose: function( selectedDate ) {
                $( "#to" ).datepicker( "option", "minDate", selectedDate );
            }
        });
        $( "#to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 2,
            onClose: function( selectedDate ) {
                $( "#from" ).datepicker( "option", "maxDate", selectedDate );
            }
        });
    });
</script>

I have been stuck on this for days, any help is greatly appreciated!!

AndrewRMillar
  • 608
  • 1
  • 7
  • 17
Brandon
  • 335
  • 2
  • 4
  • 15
  • 1
    That other question isn't Javascript, and doesn't use the jQuery UI Datepicker. – Barmar May 07 '15 at 20:05
  • Not sure what use case is but only way I can see to allow manual entry in different formats is with toggle controls to allow user to set format – charlietfl May 07 '15 at 20:38

1 Answers1

0

Please find working fiddle

It is created based on jQuery Datepicker that supports multiple formats

the only thing you have to remember is to set constraint input flag as false

$(function() {
  $("#datepicker").datepicker({
    constrainInput: false
  })
});
Community
  • 1
  • 1
Piotr Sz
  • 81
  • 1
  • 4