JqueryUI Datepicker: Uncaught TypeError: Cannot re

2020-06-02 04:33发布

I am developing a asp.net MVC4 project where i use lots of JqueryUI datepicker.

For one of my date picker when i tried to click on datepicker image i am getting some error like,

Uncaught TypeError: Cannot read property 'settings' of undefined                jquery-ui-1.10.3.min.js:9

Html

<div>
<input type="text" id="tsDte"  style="font-size: 14px;width: 50%" >              
                <img src="~/Images/dayPicker.png" onclick="tsDatePickerClick()" style="vertical-align:bottom"/>
</div>

Javascript

var currentDate = new Date();

$("#tsDte").datepicker({
    dateFormat: 'yy-mm-dd',
    maxDate: 0,
    changeYear: true 
}).attr('readonly', 'readonly');
$("#tsDte").datepicker("setDate", currentDate);


function tsDatePickerClick() {
    $("#tsDte").datepicker('show');
}

Here i have a Textfield and a datepicker image.When i click on datepicker image datepicker will popup .

i have followed the similar way in other datepicker and they are working fine.I have only problem with this date picker.

Any help is appreciated.

5条回答
看我几分像从前
2楼-- · 2020-06-02 04:41

In my case, this was caused because I had an span with id date and the input had the same id. Giving the input a different id solved the problem.

查看更多
一夜七次
3楼-- · 2020-06-02 04:42

I think your datepicker wasn't created correctly, so when you call show, it expects a settings object.

Probably you didn't create it inside $(document).ready, you should have:

$(document).ready(function(){      //Add this line (and it's closing line)
    var currentDate = new Date();

    $("#tsDte").datepicker({
        dateFormat: 'yy-mm-dd',
        maxDate: 0,
        changeYear: true 
    }).attr('readonly', 'readonly');
    $("#tsDte").datepicker("setDate", currentDate);
});

Hope this helps. Cheers

查看更多
男人必须洒脱
4楼-- · 2020-06-02 04:46

Had the same issue because I had both @Html.TextBoxFor(m => m.StartDate, "{0:dd/MM/yyyy}", new { @class = "DatePicker" }) and @Html.HiddenFor(m => m.StartDate)

in the same form on my view.

查看更多
一夜七次
5楼-- · 2020-06-02 04:55

That same error will be shown if you try to open a datepicker on an input field who has the class "hasDatepicker" assigned. Simply remove this class in the html.

Before:

<input type="text" value="01/01/2014" class="hasDatepicker">

After:

<input type="text" value="01/01/2014">
查看更多
何必那么认真
6楼-- · 2020-06-02 04:55

You are including the jquery-ui-1.10.3.min.js library.

Your issue is caused by duplicating your jQuery UI core scripts.(check if you are including any other librady such as jquery-ui-1.10.3.drag-drop.min.js .

Load just them once, and your issue will go away.

查看更多
登录 后发表回答