Anybody knows how can I display some dates from mysql table into bootstrap datepicker js code? Also mindate needed to be today() date.
Any help would be appreciated!
js code:
<script type="text/javascript">
var todayDate = new Date().getDate();
var datepicker, config;
config = {
format: 'yyyy-mm-dd',
uiLibrary: 'bootstrap4',
disableDates: [<?php while ($off = $daysoff->fetch(PDO::FETCH_ASSOC)) { echo implode("'",$off['day'],"', ");} ?>],
disableDaysOfWeek: [0],
minDate: '<?php echo date(); ?>'
};
$(document).ready(function () {
datepicker = $('#datepicker').datepicker(config);
$('#ddlLanguage').on('change', function () {
var newLang = $(this).val();
config.locale = newLang;
datepicker.destroy();
datepicker = $('#datepicker').datepicker(config);
disableDates: [new Date(2017,10,11), '20/07/2018'];
});
});
</script>
and mysql query:
select day from daysoff where status='Active'
Solved!
<?php while ($off = $daysoff->fetch(PDO::FETCH_ASSOC)) { $offs[] = $off['day']; $json_array = json_encode($offs);} ?>
<script type="text/javascript">
var arrayObjects = <?php echo $json_array; ?>;
var todayDate = new Date().getDate();
var datepicker, config;
config = {
format: 'yyyy-mm-dd',
uiLibrary: 'bootstrap4',
disableDates: arrayObjects,
disableDaysOfWeek: [0],
minDate: new Date(new Date().setDate(todayDate -1)),
maxDate: new Date(new Date().setDate(todayDate +30))
};
$(document).ready(function () {
datepicker = $('#datepicker').datepicker(config);
$('#ddlLanguage').on('change', function () {
var newLang = $(this).val();
config.locale = newLang;
datepicker.destroy();
datepicker = $('#datepicker').datepicker(config);
});
});
</script>
Related
To select a date range, I use the Jquery UI Datepicker plugin. I use a code that shows the number of days when choosing a period.
Register Datepicker jQuery plugin:
add_action('wp_enqueue_scripts', 'enabling_date_picker');
function enabling_date_picker() {
// Only on front-end and product page
if (is_product() && !is_wc_endpoint_url()):
// Load the Datepicker jQuery-ui plugin script
wp_enqueue_style('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css');
wp_enqueue_script('jquery-ui-datepicker');
endif;
}
Plugin Initialization:
// The jQuery script
add_action('wp_footer', 'rental_date_jquery_script');
function rental_date_jquery_script() {
// Only on front-end and product page
if (is_product() && !is_wc_endpoint_url()):
?>
<script>
var from = new Date();
var to = new Date();
var dayDiff = 1;
$(function() {
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat: "dd.mm.yy",
minDate: 0,
maxDate: 14,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
if (this.id == "from") {
from = $(this).datepicker('getDate');
if (!(to == "")) {
update_days()
}
}
if (this.id == "to") {
to = $(this).datepicker('getDate');
update_days()
}
}
});
});
function update_days() {
dayDiff = Math.ceil((to - from) / (1000 * 60 * 60 * 24));
$("#days").empty()
$("#days").append(dayDiff)
}
</script>
<?php
endif;
}
But for some reason, the Datepicker does not work and the calendar form is inactive.
// Add a custom field before single add to cart
add_action('woocommerce_before_variations_form', 'display_rental_date_custom_fields', 5);
function display_rental_date_custom_fields() {
echo '<div>
<h3>From:</h3>
<input id="from" type="text" name="from" readonly />
</div>
<div>
<h3>To:</h3>
<input id="to" type="text" name="to" readonly />
</div>
<div>
<span>You have chosen: </span>
<span id="days">< /span> days.
</div>';
}
How to fix my code so that the Datepicker works correctly?
Because You used a function outside jquery. pls try this
<script>
jQuery(function($) {
var from = new Date();
var to = new Date();
var dayDiff = 1;
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat: "dd.mm.yy",
minDate: 0,
maxDate: 14,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
if (this.id == "from") {
from = $(this).datepicker('getDate');
if (!(to == "")) {
update_days()
}
}
if (this.id == "to") {
to = $(this).datepicker('getDate');
update_days()
}
}
});
function update_days() {
dayDiff = Math.ceil((to - from) / (1000 * 60 * 60 * 24));
$("#days").empty()
$("#days").append(dayDiff)
}
});
</script>
Having trouble with this page loading my google map correctly. I am trying to help a friend with this but I am stumped. The script to call in the API key is in there once but I am getting the following errors:
You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.
Invalid Map Key
Am I formatting this wrong?
<?php
$lat = 41.01413965527589;
$long = -102.53826150000003;
$pg_lat = get_field('pg_latitude');
$pg_long = get_field('pg_longitude');
if ( !is_null($pg_long) ) {
$long = $pg_long;
}
if ( !is_null($pg_lat) ) {
$lat = $pg_lat;
}
$map_theme = get_field('pg_map_styles');
$styles_file = get_template_directory() . '/assets/styles/map_styles.json';
$map_styles = file_get_contents($styles_file);
?>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AlzaSyBYE1TZJEILsqvtODWyqh0okG7Ts1PNzv8&callback=initMap"
type="text/javascript"></script>
<script>
function initialize() {
var map;
var layer_0;
var layer_1;
var styles = <?php echo $map_styles; ?>;
var map_style = [];
var user_style = styles['<?php echo $map_theme; ?>'];
if (user_style && user_style['style'] != 'undefined') {
map_style = user_style['style'];
}
else {
var default_style = styles['Light Dream'];
if (default_style && default_style['style'] != 'undefined') {
map_style = default_style['style'];
}
}
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $long; ?>),
zoom: 15,
styles: map_style
});
layer_0 = new google.maps.FusionTablesLayer({
suppressInfoWindows: true,
clickable: false,
query: {
select: "col8",
from: "13zAsmjWdE-uVeVPkr-1qqUQGfZFgPBnBwbNpsWEE"
},
map: map,
styleId: 2,
templateId: 2
});
layer_1 = new google.maps.FusionTablesLayer({
query: {
select: "col2",
from: "1nhy-62Mdybjlipp3_kPrmZb_E4Z7fFjBVhNarqGk"
},
map: map,
styleId: 2,
templateId: 2
});
}
window.onload = initialize;
</script>
Your callback function is "initialize" so put this function in url after api key and also re-create api. and then try it.
var FromEndDate = new Date();
$('.conv_datetimepicker').datetimepicker({
format: 'MM/dd/yyyy hh:mm:ss',
endDate: FromEndDate,
autoclose: true
});
Use this, if you are using the Bootstrap DateTimePicker from http://eonasdan.github.io/bootstrap-datetimepicker/ :
function ValidateConvTime() {
var eventTime = $("#conv_datetimepicker").data('DateTimePicker').date();
var currentTime = new Date();
if (eventTime > currentTime) {
alert("error")
}
}
<!DOCTYPE html>
<html>
<head>
<link href='../fullcalendar.css' rel='stylesheet' />
<link href='../fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='../lib/moment.min.js'></script>
<script src='../lib/jquery.min.js'></script>
<script src='../lib/jquery-ui.custom.min.js'></script>
<script src='../fullcalendar.min.js'></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
editable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: "http://localhost/fullcalendar/demos/events.php",
// Convert the allDay from string to boolean
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Sample Textbox:');
if (title) {
start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost/fullcalendar/demos/add_events.php',
data: 'title='+ title+'&start='+ start +'&end='+ end ,
type: "POST",
success: function(json) {
alert('Added Successfully');
}
});
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
eventDrop: function(event, delta) {
var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost:8888/fullcalendar/update_events.php',
data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
type: "POST",
success: function(json) {
alert("Updated Successfully");
}
});
},
eventResize: function(event) {
var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost:8888/fullcalendar/update_events.php',
data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
type: "POST",
success: function(json) {
alert("Updated Successfully");
}
});
}
});
});
</script>
<style>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
I have implemented the fullcallendar with php mysql.I am able to query database and get the events from table.But I am not able to add the events in proper format.
start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
if i use formatdata add function not working.If i remove this, its working but inserting in db as 0000-00-00 for date and time.I dont know what am doing wrong.I have tried everything to sort this out.Can anybody help me out in this???
Try this:
var start = Year+":"+Month+":"+Date+" "+hour+":"+min+":"+sec;
var end = Year+":"+Month+":"+Date+" "+hour+":"+min+":"+sec;
Instead
start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
It will work for database insertion
Add this before the previous code:
var Year = date.getFullYear();
var Month = date.getMonth() + 1;
var Date = date.getDate();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
I'm trying to close an infowindow wich displays a streetview. When I click on the map, the infowindow is not closed. Also when I click over other marker an infowindow is opened but the streetview opens in the previous infowindow. So I need that the infowindow get closed and displays the streetview. Here is the code: thank you for your help.
Best regards.
function paradascamiones() {
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
var Boton = document.getElementById('Boton').value;
var textboxImei = document.getElementById('imei').value;
var textboxFecha = document.getElementById('fecha').value;
var textboxFechaFin = document.getElementById('fechaFin').value;
var textboxDesdeHora = document.getElementById('desdeHora').value;
var textboxHastaHora = document.getElementById('hastaHora').
downloadUrl("paradas.asp?imei="+textboxImei+"&fecha="+textboxFecha+" "+textboxDesdeHora+"&fechaFin="+textboxFechaFin+" "+textboxHastaHora,
function(data) {
var xml = xmlParse(data);
var markersParadas = xml.documentElement.getElementsByTagName("marker");
var position = [];
for (var i = 0; i < markersParadas.length; i++) {
var lat = parseFloat(markersParadas[i].getAttribute("lat"));
var lng = parseFloat(markersParadas[i].getAttribute("lng"));
var myLatlngParadas = new google.maps.LatLng(lat, lng);
var fechaInicio = markersParadas[i].getAttribute("fechaInicio");
var fechaFinal = markersParadas[i].getAttribute("fechaFinal");
var diferencia = markersParadas[i].getAttribute("diferencia");
var datearray = diferencia.split("/");
var newDate = datearray[1] + '/' + datearray[0] + '/' + datearray[2];
var aFecha = new Date(newDate);
var hours = aFecha.getHours();
var minutes = aFecha.getMinutes();
var seconds = aFecha.getSeconds();
var markerParadas = createMarkerParadas(myLatlngParadas, hours, minutes, seconds, fechaInicio);
myMarkersParadas.push(markerParadas);
}//finish loop
}); //end download url
}
function createMarkerParadas(myLatlngParadas, hours, minutes, seconds, fechaInicio) {
var contentString = '<div id="content" style="width:350px;height:300px;"> </div>';
var infoWindow = new google.maps.InfoWindow({
content: contentString
});
var image2 = '/artworks/icons/stop.png';
var markerParadas = new google.maps.Marker({
position: myLatlngParadas,
map: map,
title: " my info ",
icon: image2
});
google.maps.event.addListener(markerParadas, "click", function () {
infoWindow.open(map, markerParadas);
var pano = null;
google.maps.event.addListener(infoWindow, 'domready', function () {
if (pano != null) {
pano.unbind("position");
pano.setVisible(false);
}
pano = new google.maps.StreetViewPanorama(document.getElementById("content"), {
navigationControl: true,
enableCloseButton: false,
addressControl: true,
linksControl: false
});
pano.bindTo("position", markerParadas);
pano.setVisible(true);
});
google.maps.event.addListener(infoWindow, 'closeclick', function () {
pano.unbind("position");
pano.setVisible(false);
pano = null;
});
});
return markerParadas;
}
In your code, at least you should change that defining the infowindow variable as global scope.
your code
function createMarkerParadas() {
var infoWindow = new google.maps.InfoWindow({
content : contentString
});
...
}
Change to like this;
<script type="text/javascript">
var map, infowindow;
...
function createMarkerParadas() {
infoWindow = new google.maps.InfoWindow({
content : contentString
});
....
}
</script>