Jquery datepicker range (mindate maxdate) not working

I am trying to set the range for the jquery datepicker that I have in my form, but when I open the form, it allows me to select any date.

  <input class="span2 datepicker" name="tw#local#changeRequest#DeliveryDate" type="text" id="dp1">


 <!-- jQuery -->
 <script type="text/javascript" src="<#=tw.system.model.findManagedFileByPath('jquery-1.7.2.min.js', TWManagedFile.Types.Web).url;#>"></script>

 <!-- Datepicker Script -->
 <script type="text/javascript" src="<#=tw.system.model.findManagedFileByPath('bootstrap-datepicker_new.js', TWManagedFile.Types.Web).url;#>"></script>

 <script type="text/javascript">
 $(document).ready(function(){

 $( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });

 });
 </script>
+3
source share
5 answers

As far as I know, this should be done as follows:

$("#datepicker").datepicker('option', {minDate: <some date>, maxDate: <some date>});

What you are missing is that you must install them using the "option" option.

+9
source
$('#datepicker').datepicker({
            maxDate: '0'}),

Use '0'to select the maximum date today

You can also reference jQueryUI Api

+3
source
$('#datepicker').datepicker({
                maxDate: '+1m',
                minDate: '-20d',
                });

min max date , . - MaxDate jquery ui datepicker.

+1

One more thing, you may have noticed this already, but your selector is looking for an identifier as "datepicker". Whereas your date picker is your CLASS. So I think you need to change "#datepicker" to ".datepicker".

0
source

just add a controller if you use angularjs $ scope.today = new Date ()

and in html min-date = "today"

0
source

Source: https://habr.com/ru/post/1670364/


All Articles