$(...).datepicker is not a function - javascript

Datepicker canĀ“t run in this page, but the script of jquery-ui is imported.
Where is the conflict? Thanks.
Datepicker is not a function
This is my script
$( document ).ready(function() {
var fecha = "";
$( "#datepicker" ).datepicker({
dateFormat: "yy-mm-dd",
});
});
$( "#datepicker" ).change(function(){
fecha = this.value;
$.post( "tablaUsuarioPlanta.php",{fecha : fecha},function(data){
$("#tabla").html(data);
});
});
This is the HTML
<p>Date: <input type="text" id="datepicker" size="30"></p>
And the scripts load on the page
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<!-- Bootstrap Core CSS -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="../css/simple-sidebar.css" rel="stylesheet">
<!--JQUERY-->
<!--<script src="../js/jquery.js"></script>-->
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>

You are using two version of JQuery that creates the confliction . Use only one instead of two.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="../css/simple-sidebar.css" rel="stylesheet">
<!--JQUERY-->
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>

Related

jQuery datepicker not working due to JavaScript version conflict

I have created a web page with a JavaScript datetimepicker but it is not working due to another jQuery version being called to the page for another purpose. How would I make datetimepicker or datepicker work with any version of JavaScript?
$(function() {
$("#datepicker").datepicker();
});
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="style/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="style/qweerwer.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
var jQuery_3_1_1 = $.noConflict(true);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
var jQuery_1_11_1 = $.noConflict(true);
</script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<label class="control-label"> Event Date </label>
<div class="form-group ">
<input style='max-width: 250px;' readonly="" name="eventdate" placeholder="Event Date" id="datepicker" class="form-control">
</div>
You are missing reference to jQuery UI library, where datepicker function is defined. Add this line to your HTML.
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Use the following js library and css:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

I have this error : $(...).datepicker is not a function

I try to use a datepicker, but it doesn't work.
I have this error : $(...).datepicker is not a function
I use many frameworks and librairy (Adminlte, bootstrap, chartjs, datatable). And I think that there is a conflicts between they.
$(document).ready(function() {
$('#datepicker').datepicker();
$('#datepicker').on("changeDate", function() {
$('#my_hidden_input').val(
$('#datepicker').datepicker('getFormattedDate')
);
});
});
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AdminLTE 2 | Dashboard</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.6 -->
<link rel="stylesheet" href="./css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="./css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="./css/skin-black-light.css">
<!-- CSS Table -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<!-- My Style -->
<link rel="stylesheet" href="./css/style_general.css">
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet/less" type="text/css" href="./less/dropdown.less" />
<link rel="stylesheet/less" type="text/css" href="./less/sprites.less" />
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini fixed">
<div class="form-group">
<label>Date</label>
<div class="input-group date margin-bottom-10" id="datetimepicker1">
<input type="text" class="form-control" id="date" name="date" placeholder="DD/MM/YYY">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
<!-- jQuery 2.2.3 -->
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="./js/bootstrap.min.js"></script>
<!-- AdminLTE App -->
<script src="./js/app.min.js"></script>
<!-- ChartJS 1.0.1 -->
<script src="./js/Chart.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="./js/demo.js"></script>
<!-- SlimScroll 1.3.0 -->
<script src="./js/jquery.slimscroll.min.js"></script>
<!-- JS table -->
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="./js/test_table.js"></script>
<script src="./js/js.js"></script>
</body>
</html>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
var j = jQuery.noConflict();
j( function() {
j( "#datepicker" ).datepicker();
} );
</script>
Please try it this way. It is working fine. Same object is defined and used by jquery so its conflict try above trick its work fine..
I think datepicker is available in JQuery UI but you didn't include those library files. when I include the below files there is no such error $(...).datepicker
please include these file and check
[link] https://code.jquery.com/ui/1.12.1/jquery-ui.js
[link] https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css
Make sure that you include that datapicker.js library on the page that you use it on. Make sure that the link / local file exists. It may be a loaded from a different file if you are using bootstrap / framework.
This is the most common reason.
You can follow like this. This works for me.
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
The JS coding for the Date Picker I use.
<script>
$(document).ready(function(){
// alert ('Cliecked');
var date_input=$('input[name="orangeDateOfBirthForm"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
var options={
format: 'dd/mm/yyyy',
container: container,
changeYear: true,
changeMonth: true,
todayHighlight: true,
autoclose: true,
yearRange: "1930:2100"
};
date_input.datepicker(options);
});
</script>
The HTML Coding:
<input type="text" id="orangeDateOfBirthForm" name="orangeDateOfBirthForm" class="form-control validate" required>
<label data-error="wrong" data-success="right" for="orangeForm-email">Date of Birth</label>
If datepicker does not work due to conflict jquery, then try this way. It will work.
<script>
$.noConflict();
jQuery( document ).ready(function( $ ) {
(function($){"use strict";
var $window=$(window)
var datepick=$('.date-pick')
if($(datepick).length){$(datepick).datepicker({format:"dd/mm/yyyy"});}
})(jQuery);
});
</script>
<script type="text/javascript" src="js/bootstrap-datepicker.js"></script> <!-- datepicker js-->
There is no conflict with using jQuery and Datepicker together.
This error - "$().datepicker is not a function" - is almost always a conflict because of a second instance of jQuery being loaded.
Look for a second instance of jQuery being loaded somewhere.
I have gone through all your js files.
Noted that you are using AdminLTe for your js and css.
In that case, check again the the example in Forms > Advanced Elements in left panel.
I think you missed out the bootstrap datepicker: Try searching for this js file in AdminLTe Example: <link rel="stylesheet" href="../../plugins/datepicker/datepicker3.css">
Inclue JqueryUI
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

why don't BOTH fullCalendar and datePicker work?

currently the code for the calendar functions, but the datePicker doesn't
if i copy/paste so that the date picker code comes second it functions, but the calendar doesn't.
fullcalendar source http://fullcalendar.io/ datepicker source https://jqueryui.com/datepicker/#min-max
<meta charset="utf-8">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https:/resources/demos/style.css">
<script type="text/javascript">
$(function() {
$( "#datepicker" ).datepicker({ minDate: +1, maxDate: "+1Y" });
});
</script>
<!-- code above is the code for the datepicker -->
<!-- code below is the code for the calendar -->
<link rel='stylesheet' href='fullcalendar-2.6.1(1)/fullcalendar-2.6.1/fullcalendar.css' />
<script src='fullcalendar-2.6.1(1)/fullcalendar-2.6.1/lib/jquery.min.js'></script>
<script src='fullcalendar-2.6.1(1)/fullcalendar-2.6.1/lib/moment.min.js'></script>
<script src='fullcalendar-2.6.1(1)/fullcalendar-2.6.1/fullcalendar.js'></script>
<script type="text/javascript">
$(document).ready(
function(){
$('#calendar').fullCalendar({
weekends:false,
defaultView:'agendaWeek',
header: {
left:'prev,today,next',
center:'title',
right:'month,agendaWeek'
},
});
});
As pointed out simoultaniously by #Guruprasad and myself, your file inclusions are a mess.
It seems you're new so for this time here's the correct way to do it.
You don't need all the $(func... since you're using document.ready event to fire before calling the functions which means that jquery is available at this point.
Hope it helps !
<meta charset="utf-8">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel='stylesheet' href='fullcalendar-2.6.1(1)/fullcalendar-2.6.1/fullcalendar.css' />
<link rel="stylesheet" href="https:/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src='fullcalendar-2.6.1(1)/fullcalendar-2.6.1/lib/moment.min.js'></script>
<script src='fullcalendar-2.6.1(1)/fullcalendar-2.6.1/fullcalendar.js'></script>
<script type="text/javascript">
$(document).ready(
$( "#datepicker" ).datepicker({ minDate: +1, maxDate: "+1Y" });
$('#calendar').fullCalendar({
weekends:false,
defaultView:'agendaWeek',
header: {
left:'prev,today,next',
center:'title',
right:'month,agendaWeek'
},
});
});

Uncaught TypeError: Cannot read property 'addMethod' of undefined

jQuery(document).ready(function () {
//alert("HIQ");
$('.mySelectCalendar').datepicker({ firstDay: 1, dateFormat: "dd.mm.yy" });
$.validator.addMethod(
'date',
function (value, element, params) {
if (this.optional(element)) {
return true;
};
var result = false;
try {
$.datepicker.parseDate('dd.mm.yy', value);
result = true;
} catch (err) {
result = false;
}
return result;
},
''
);
});
I get error as "Uncaught TypeError: Cannot read property 'addMethod' of undefined"
_layout as this
#ViewBag.Title
<!-- jQuery -->
<script src="~/App_Themes/ThemeBlue/assets/js/jquery203.js"></script>
<script src="~/App_Themes/ThemeBlue/assets/js/jquery.min.js"></script>
<script type="text/javascript">
var jQuery_2_0_3 = $.noConflict(true);
</script>
<!-- Picker UI-->
<script src="~/App_Themes/ThemeBlue/assets/js/jquery-ui.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<!--Validation -->
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<link href="~/App_Themes/ThemeBlue/css/validation.css" rel="stylesheet" />
<script type="text/javascript">
var jQuery_1_7_0 = $.noConflict(true);
</script>
<!-- Bootstrap -->
<link href="~/App_Themes/ThemeBlue/dist/css/bootstrap.css" rel="stylesheet" media="screen" />
<link href="~/App_Themes/ThemeBlue/assets/css/custom.css" rel="stylesheet" media="screen" />
<!-- bin/jquery.slider.min.js -->
<script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jshashtable-2.1_src.js"></script>
<script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jquery.numberformatter-1.2.3.js"></script>
<script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/tmpl.js"></script>
<script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jquery.dependClass-0.1.js"></script>
<script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/draggable-0.1.js"></script>
<script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jquery.slider.js"></script>
<!-- Javascript -->
<script src="~/App_Themes/ThemeBlue/assets/js/initialize-loginpage.js"></script>
<script src="~/App_Themes/ThemeBlue/assets/js/jquery.easing.js"></script>
<script src="~/App_Themes/ThemeBlue/assets/js/customTravel.js"></script>
<!-- Load Animo -->
<script src="~/App_Themes/ThemeBlue/plugins/animo/animo.js"></script>
<script src="~/App_Themes/ThemeBlue/dist/js/bootstrap.min.js"></script>
<!-- Carousel -->
<link href="~/App_Themes/ThemeBlue/examples/carousel/carousel.css" rel="stylesheet" />
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
<!-- Fonts -->
<link href='http://fonts.googleapis.com/css?family=Lato:400,100,100italic,300,300italic,400italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:700,400,300,300italic' rel='stylesheet' type='text/css'>
<!-- Font-Awesome -->
<link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/assets/css/font-awesome.css" media="screen" />
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/assets/css/font-awesome-ie7.css" media="screen" /><![endif]-->
<!-- REVOLUTION BANNER CSS SETTINGS -->
<link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/css/fullwidth.css" media="screen" />
<link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/rs-plugin/css/settings2.css" media="screen" />
<!-- Picker UI-->
<link rel="stylesheet" href="~/App_Themes/ThemeBlue/assets/css/jquery-ui.css" />
<!-- bin/jquery.slider.min.css -->
<link rel="stylesheet" href="~/App_Themes/ThemeBlue/plugins/jslider/css/jslider.css" type="text/css">
<link rel="stylesheet" href="~/App_Themes/ThemeBlue/plugins/jslider/css/jslider.round.css" type="text/css">
<!-- Animo css-->
<link href="~/App_Themes/ThemeBlue/plugins/animo/animate_animo.css" rel="stylesheet" media="screen">
<!-- end -->
I write web application in MVC and could not solve this problem.
COuld you help me?
Your error:
Uncaught TypeError: Cannot read property 'addMethod' of undefined
It simply means that JavaScript cannot find the addMethod method, which is built into the jQuery Validate plugin. jQuery or jQuery Validate was not included properly... the file(s) cannot be found or jQuery is broken...
Your head section is a mess with multiple versions of jQuery and .noConflict() applied inconsistently.
Notice how you've define .noConflict() just after this particular version of jQuery is included?
<!--Validation -->
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
....
<script type="text/javascript">
var jQuery_1_7_0 = $.noConflict(true); // <- this
</script>
So for the validation section, the name jQuery_1_7_0 must replace every instance $ just within your validation code.
jQuery_1_7_0(document).ready(function () {
jQuery_1_7_0.validator.addMethod( ....
I've only pointed out one example. You've also included a version of jQuery without .noConflict() just above your validation section.
These multiple versions of jQuery need to be resolved, either by removing the duplicates and leaving one version or by properly using .noConflict() after each version is included.
IMO, it's best to only use one version of jQuery.
Documentation: Using jQuery .noConflict()
Add jquery.validate.js file and jquery.min.js if you have not included and then write your code of js for add 'addMethod' method.
for me it was fixed when i put $.validator.addMethod method out of $(document).ready(function(){ !
and there was no need to use noConflict() method...
if you use Webpack(or Laravel mix like me) check the order of compiled js which sometimes it put validator before jquery and that causes this error

JQuery timepicker flows out of HTML text box

I'm trying to implement a time picker, in a text box. But the times are flowing outside of the box.
Does anyone know what the issue could be?
Inside my HTML file:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="jquery.timepicker.js"></script>
<script>
$(function() { $('#time_picker').timepicker({ 'step': 15 }); });
</script>
...
<label> Departure Time: </label>
<input type="text" id="time_picker" name="depart_time"> <br>
This will work fine
<link href="jquery-ui.css" rel="stylesheet" />
<link href="jquery.timepicker.css" rel="stylesheet" />
<script src="jquery-1.9.1.js"></script>
<script src="jquery-ui.js"></script>
<script src="jquery.timepicker.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#time_picker').timepicker();
});
</script>

Categories