Issue with DateTime picker functionality not functioning as expected

My MVC5 project is having trouble with adding a date picker. I keep getting an error in the JS code and I'm not sure what I'm missing. I tried adding Nuget for datetime picker but it's still not working. The console error is:

Uncaught TypeError: undefined is not a function Create:93
(anonymous function) Create:93

Any ideas on what I might be missing here?

This is the entire page code:

I can provide the project if needed, it's a very simple project with just 3 fields.

@model TestropDownCreate.Models.TestModel

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

<script src="~/Scripts/jquery-1.10.2.min.js"></script>    

<script src="~/Scripts/moment.js"></script>    
<script src="~/Scripts/moment-datepicker.js"></script>            
<link href="~/Content/moment-datepicker/datepicker.css" rel="stylesheet" /> 
<link href="~/Content/jquery.datetimepicker.css" rel="stylesheet" />
<link href="~/Content/bootstrap-datepicker.css" rel="stylesheet" />    



<script src="~/Scripts/bootstrap-datetimepicker.js"></script>    

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Model</h4>
        <hr />
        @Html.ValidationSummary(true)

        <div class="form-group">
            @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name) 

                @Html.ValidationMessageFor(model => model.Name)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.SelectedGender, new { @class = "control-label col-md-2" })
            <div class="col-md-10">

                @Html.DropDownListFor(model => model.SelectedGender, Model.Gender)

            </div>
        </div>

        <div class="form-group">
            <div class="input-append date control-label col-md-2">
                Date
                <input data-format="yyyy-MM-dd" type="text" id="datetimepicker4" />
                <span class="add-on">
                    <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                </span>
            </div>

        </div>


       // It's there where I'm having the error -->

            <script type="text/javascript">

                $(function () {

                    $('#datetimepicker4').datepicker({

                        pickTime: false

                    });

                });

            </script>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </div>
        </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Answer №1

One issue I noticed in the code is the repetition of including the same script twice - once in its regular version and then again in its minified version.

For example:

<script src="~/Scripts/moment-datepicker.js"></script>
<script src="~/Scripts/moment-datepicker.min.js"></script>

You should only include one of these versions. Therefore, you can either include:

<script src="~/Scripts/moment-datepicker.js"></script>

OR

<script src="~/Scripts/moment-datepicker.min.js"></script>

The same applies to other scripts that are mistakenly included twice. By rectifying this error, it should resolve your problem unless there are additional errors present in your code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In Internet Explorer, HTML elements may not always align seamlessly with other elements on the page

What is causing the alignment issue with the Available Times table, Assessor Notes textbox, and Booking Notes textbox in Internet Explorer, while they appear perfectly aligned in Firefox? Here is my CSS: <style type="text/css" media="screen"> h ...

Combining all CSS into a unified file in Next.js with the help of mini-css-extract-plugin

While working with Nextjs and using Sass for styling, I noticed that in production mode, multiple CSS files are being loaded sequentially. I aim to optimize this by loading only one CSS file. After researching, I came across the MiniCssExtractPlugin which ...

Guide to assigning unique identifiers to all elements within an array using JavaScript

I have an array of objects with numeric keys that correspond to specific data values. I am attempting to restructure this object in a way that includes an 'id' field for each entry. Here is the original object: [ { "1": "data1", "5": "d ...

Adjusting the mesh position in WebGL/Three.js

Seeking some guidance on three.js. How can I apply an offset to a mesh? You can find the basic code here: I am looking to set a position offset and have that point serve as the rotation reference. I attempted: mesh.applyMatrix( new THREE.Matrix4().makeTr ...

Chai spy does not recognize sinon stubbed functions when verifying function calls

I am working with two asynchronous functions that return bluebird promises: Async1: function() { return new Promise(function(resolve, reject) { execute(query) .then(function(resp) { resolve(resp); }) .catch(function(err) { ...

Having trouble getting automapper-ts registered in the Global Context within an Angular application - Reference to App is Undefined

Ever since the upgrade to Angular 18, it seems like the node package automapper-ts has stopped functioning properly. When attempting to set up Automapper in the global context, the issue arises where app is undefined, resulting in the failure to resolve t ...

Utilizing jQuery to display only one element from a given pair

Managing a set of message elements that come in pairs and should show or hide opposite each other can be quite tedious. While I have managed to make it work with jQuery, the code seems to be quite verbose: if (conditionA) { $("#a1").show(); $("#a2 ...

How to retrieve variables passed from one Jade file to another Jade file

I've successfully set up a nodejs project that's linked to mongodb. In one of my jade files, I have a student list populated from the database, each with an edit button. Clicking on the edit button should take the user to another jade file called ...

Developing a trivia game using HTML and JavaScript

I'm in need of some serious assistance with creating a quiz using HTML. My goal is to have a web page where users can visit, take a quiz, and have their responses stored. Unfortunately, I don't have the knowledge or skills required to do this on ...

Send a property as a string, then transform the string back into JavaScript

I am in the process of creating a versatile carousel that will cater to various conditions. Therefore, I need to set the "imageQuery" on my display page as a string and then make it work as executable javascript within my carousel. The query functions pr ...

Utilizing jQuery to Sort Table Rows based on an Array of Class Names

I have a table containing values and a filter option where users can select multiple values to filter the table. I want to create a filter with numbers ranging from 1 to 10, and assign class names like filter_1, filter_2, filter_3, etc. to each table row ( ...

Is it preferred to utilize v-show in combination with v-for?

I understand that using "v-if" with "v-for" is discouraged, but I'm unsure about the case of "v-show" since it simply toggles the display attribute. Here is the code for reference. Essentially, I am trying to switch between 3 different types of fi ...

Investigating unsuccessful requests in node.js

Here is my code: var request = require('request'); function Service(){ this._config = require('../path/to/config.json'); } Service.prototype.doThing = function(){ return new Promise(function(resolve, reject){ request.post(url, ...

Employing Bootstrap4 in conjunction with Rails 5

After following the official guide and checking out this post with no success, I'm in need of some help. Can anyone shed some light on this? (source on github) Here is my Gem file: ... #bootstrap gem 'bootstrap', '~> 4.0.0.alpha3.1 ...

ExpressJS authentication -> PassportJS: Issue with setting headers after they have been sent

Currently, I am implementing authentication in Express.js using Passport.js. Below is the code snippet from my login.js file: passport.use(new LocalStrategy( function(username, password, done) { //console.log(username); Usercollectio ...

Restrict the selection of dates in the jQuery UI datepicker by disabling public holidays, weekends, the next day after 10am, and only allowing Tuesday, Wednesday, and Thursday as

I found a code snippet on disabling weekends, public holidays, and the next day after 10 am using JQuery UI Datepicker. However, I'm facing an issue where I want to restrict selections to only Tuesday, Wednesday, and Thursday. // JavaScript logic for ...

Looking to position a dropdown at the right edge using CSS grid?

I am currently in the process of familiarizing myself with css grid. My goal is to align a responsive drop down menu to the right using css grid techniques. I understand that there are numerous approaches to achieve this relatively straightforward task, bu ...

Revise every Express.js model

I am looking to implement a put request in Express to update all the models in my collection. Consider this example of a MongoDB collection: { '_id': '123' 'name' : 'john', 'last' : 'smith ...

Seeking a JavaScript tool specialized in compressing POST data?

Currently working on a chrome extension that sends HTML strings to a server using POST requests. Interested in compressing these large strings before sending them. Wondering if there are any JavaScript libraries that can help with this? ...

Error: Attempting to access the 'findAll' property of an undefined value in the context of MariaDB and ExpressJs

TypeError: Cannot read property 'findAll' of undefined findAll function is causing an error, however the Connection was successful. Also, a database named managers has been created. app.js models index.js maria manager.model.js bin ww ...