0

I am using jQuery UI and trying to use datepicker. It works well but if I want to set current date to the field then it does not work. I have tried some but no luck. My attempts are below :

My input:

<g:textField id="admissionDate" class="form-control datepicker" name="admissionDate"
                                             required=""/>

Set date attempt on document ready:

$("#admissionDate").datepicker({
            dateFormat: 'yy/mm/dd'
        }).datepicker("setDate",  "08/03/2016");

Also tried:

$('.datepicker').datepicker();
$('.datepicker').datepicker("setDate",  "08/03/2016");

It highlight the current date if clicked but no set to text field.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82

1 Answers1

0

Replacing your g:textField with input works.

$("#admissionDate").datepicker();
$('#admissionDate').datepicker( "setDate", "10/12/2012" );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<input type="text" id="admissionDate" class="form-control datepicker" name="admissionDate" style="width: 200px"/>
random
  • 7,756
  • 3
  • 19
  • 25
  • I am using jquery-1.11.1 and jquery-ui 1.12.1. Can it be the problem – Sumon Bappi Apr 29 '19 at 03:49
  • or I need other essential file for it – Sumon Bappi Apr 29 '19 at 03:50
  • As per the documentation - https://api.jqueryui.com/, `jQuery UI 1.12 supports jQuery 1.7 and newer` and you have less version. Use latest `jQuery Version`. – random Apr 29 '19 at 03:55
  • 1.7 was [released Nov 4, 2011](https://github.com/jquery/jquery/releases?after=1.7.2rc1) and 1.11.1 was [released May 2, 2014](https://github.com/jquery/jquery/releases?after=1.12.0). So 1.11.1 is newer than 1.7. – Shinjo Apr 29 '19 at 04:01
  • @Shinjo - yes, I misunderstood and that's why I deleted the comment. – random Apr 29 '19 at 04:02