I have not found another question quite like this. There are some similar with solutions like "be sure and include 'prev' and 'next' buttons" and things about timezones etc. I do not believe there is any issue with the logic or time zone or code on the backend. When I click on existing events, they work fine. I can click, drag, drop, edit, retrieve popup modal, etc. But when I click on an empty space in a date, it is inaccurate. I can see it visually selecting the wrong box. This is the case for every day of the month. The click is accurate in the top left 25% of the box. The bottom and left 75% is off by one box in that direction.
Look at May 18.
red: works perfect
yellow: selects 19th
blue: selects 26th
green: selects 25th
It is like a strange calibration issue. But if I click on an event, even if it is at the bottom of that box, like Thomas on May 5, it works just fine. Below is my js file.
function GetEventsOnPageLoad() {
$('#calendar').fullCalendar({
header: {
left: 'prev, next today',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
buttonText: {
today: 'Today',
month: 'Month',
week: 'Week',
day: 'Day'
},
selectable: true,
select: function (start) {
selectedEvent = {
eventID: 0,
start: start,
allDay: true,
};
CreateFullCalEvent(start.toISOString());
$('#calendar').fullCalendar('unselect');
},
height: 'parent',
events: function (start, end, timezone, callback) {
$.ajax({
type: "GET",
contentType: "application/json",
url: "GetEventData",
dataType: "JSON",
success: function (data) {
var events = [];
$.each(data, function (i, data) {
events.push(
{
title: data.title,
start: moment(data.start),
end: moment(data.end),
allDay: true,
backgroundColor: data.color,
id: data.id,
textColor: data.textColor
}
);
});
callback(events);
}
})
},
nextDayThreshold: '00:00:00',
editable: true,
droppable: true,
nowIndicator: true,
eventClick: function (info) {
GetFullCalEventByID(info);
},
eventDrop: function (info) {
console.log(info);
UpdateFullCalEvent(info.id, info.start.toISOString(), info.end.toISOString());
},
eventResize: function (info) {
UpdateFullCalEvent(info.id, info.start.toISOString(), info.end.toISOString());
}
})
}
function CreateFullCalEvent(start) {
window.location.href = "CreateFullCalEvent?start=" + encodeURIComponent(start);
}
function GetFullCalEventByID(eventinfo) {
$.ajax({
type: "GET",
url: "GetFullCalEventByID/" + eventinfo.id,
dataType: "JSON",
contentType: "applicaton/json; charset=utf-8",
success: function (eventdetails) {
showModal('Event Details', eventdetails, true);
}
});
}
function UpdateFullCalEvent(id, start, end) {
var object = {};
object.id = id;
object.start = start;
object.end = end;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "UpdateFullCalEvent/",
dataType: "JSON",
data: JSON.stringify(object)
});
}
function showModal(title, body, isEventDetail) {
$("MyPopup .modal-title").html(title);
if (isEventDetail == null) {
$("#MyPopup .modal-body").html(body);
$("#MyPopup").modal("show");
}
else {
var title = 'Title: ' + body.title + '</br>';
var details = 'Details: ' + body.details + '</br>';
var date = 'Date: ' + moment(body.start).format("M/D/YYYY") + '</br>';
var empName = 'Employee: ' + body.employeeName + '</br>';
url = 'Location: ' + body.url + '</br>';
var modalPop = $("#MyPopup .modal-body");
modalPop.html(title + details + date + empName + url);
$("#MyPopup.modal").modal("show");
}
}
About line 16 to 21 is the issue. It happens even if I am not calling a function at all. If I just do a popup modal like below, I can still see it highlighting and selecting the wrong day:
selectable: true,
select: function () {
showModal('Create an Event', 'Create new Event feature coming soon. For now, use create button in list view', null);
The CSS was the issue. I had
body {
zoom: 110%;
}
Apparently fullCalendar does not respond well to zoom feature of CSS. It is not a problem if the user zooms in the browser though.
Related
I would like to have a autocomplete for a textfield (tf_place), where you start to type the place name (of a German city) and it fills in the complete city name. As source I would like to use GeoNames. I already created a new user account and confirmed it.
$('[data-name="tf_place"]').autocomplete({
source: function (request, response) {
$.ajax({
url: "http://api.geonames.org/postalCodeSearchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
maxRows: 10,
country: "DE",
placename_startsWith: request.term,
username: "myUser"
},
success: function (data) {
response($.map(data.postalCodes, function (item) {
return {
label: item.postalCode + "-" + item.placeName,
value: item.postalCode + "-" + item.placeName
}
}));
}
});
},
});
What's wrong?
Edit: I tried the complete URL:
http://api.geonames.org/postalCodeSearchJSON?featureClass=P&maxRows=10&country=DE&placename_startsWith=Be&username=myUser
It works! (to make it work for you, you need to replace myUser with your own username)
So why doesn't my code work?
I've been working on a project and thus far I've been able to POST to the database using AJAX, so when the user submits data the page wont refresh but the data is still uploaded to the database.
Now what I want to do, is show those results to the user without needing to refresh the page. I've spent a lot of time trying to figure it out but right now I'm very stuck. Could anyone point me in the right direction? I've read the documentation on the website, watched hours worth of videos but still have no luck.
The code I have so far.
Script
$.ajax({
type: 'GET', //THIS NEEDS TO BE GET
url: '{{$video->id}}/shownew',
success: function (data) {
console.log(data);
$("#data").append(data);
},
error: function() {
console.log(data);
}
});
Controller
public function shownew($video)
{
$getstamps = DB::table('timestamps')
->where('videoid', '=', $video)
->orderByRaw('LENGTH(timestamp_time)', 'ASC')
->orderBy('timestamp_time', 'asc')
->get();
return response()->json(array('success' => true, 'getstamps' => $getstamps));
}
Console
{success: true, getstamps: Array(3)}
getstamps: Array(3)
0: {
timestamp_id: 128,
videoid: "5",
timestamp_name: "Title",
timestamp_time: 1,
created_at: "2017-10-04 23:28:12",
…
}
1: {
timestamp_id: 129,
videoid: "5",
timestamp_name: "1",
timestamp_time: 1,
created_at: "2017-10-04 23:41:01",
…
}
2: {
timestamp_id: 130,
videoid: "5",
timestamp_name: "1",
timestamp_time: 1,
created_at: "2017-10-04 23:41:21",
…
}
length: 3
__proto__: Array(0)
success: true
__proto__: Object
here is the solution for you problem
$.ajax({
type: 'GET', //THIS NEEDS TO BE GET
url: '{{$video->id}}/shownew',
success: function (data) {
var obj = JSON.parse(data);
var your_html = "";
$.each(obj['getstamps'], function (key, val) {
your_html += "<p>My Value :" + val + ") </p>"
});
$("#data").append(you_html); //// For Append
$("#mydiv").html(your_html) //// For replace with previous one
},
error: function() {
console.log(data);
}
});
This fixed the issue.
$.ajax({
type: 'GET', //THIS NEEDS TO BE GET
url: '{{$video->id}}/shownew',
dataType: 'json',
success: function (data) {
console.log(data);
container.html('');
$.each(data, function(index, item) {
container.html(''); //clears container for new data
$.each(data, function(i, item) {
container.append('<div class="row"><div class="ten columns"><div class="editbuttoncont"><button class="btntimestampnameedit" data-seek="' + item.timestamp_time + '">' + new Date(item.timestamp_time * 1000).toUTCString().match(/(\d\d:\d\d:\d\d)/)[0] +' - '+ item.timestamp_name +'</button></div></div> <div class="one columns"><form action="'+ item.timestamp_id +'/deletetimestamp" method="POST">' + '{!! csrf_field() !!}' +'<input type="hidden" name="_method" value="DELETE"><button class="btntimestampdelete"><i aria-hidden="true" class="fa fa-trash buttonicon"></i></button></form></div></div>');
});
container.append('<br>');
});
},error:function(){
console.log(data);
}
});
I'm returning a JSON string with an Ajax call in jQuery, I'd like to pump that data into a bar chart using jqPlot.
I got the JSON conversion code from another Stack-Overflow post, but can't understand why this isn't working. My code:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(DTO), //JSON.stringify(AnDParms), combined,
url: "GetAdmitsDischarges.asmx/GetAandD",
dataType: "json",
success: function (data) {
//do chart stuff here.
var line1 = [];
for (var prop_name in data.d) {
line1.push([prop_name, data[prop_name]])
}
var ticks = ['Admits', 'Discharges'];
var plot1 = $.jqplot('chartdiv', [line1], {
title: 'Admits & Discharges',
series: [{ renderer: $.jqplot.BarRenderer}],
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
});
//to prove the flow is working...
//alert("Data: " + data.d);
}, //end of success
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + ' ' + errorThrown + ' ' + XMLHttpRequest);
} //end of error
}); //end of ajax call
In Firebug, the value of line1 is (going from 0 to 32):
[["0", undefined],["1", undefined],...["31", undefined],["32",
undefined]]
While the value of data is:
Object { d="{"Admits":"35","Discharges":"36"}" }
Thanks for any help you can offer...
The problem is your JSON structure:
{
"Admits": "35",
"Discharges": "36"
}
You are providing a JSON object, but jqplot needs array instead:
[
["Admits", 35],
["Discharges", 36]
]
I finally figured it out with the help of Dave Ward of Encosia.com...if you've not checked out his blog, head straight there right now...it's great for all your .Net/jQuery needs.
Here is my javascript:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(DTO),
url: "GetAdmitsDischarges.asmx/GetAandD",
dataType: "json",
success: function (data) {
var jqPlotData = $.map(data.d, function (value, key) {
if (key != "__type") {
return [value]; //was key, value
}
});
var ticks = ['Admits', 'Discharges'];
var plot1 = $.jqplot('chartdiv', [jqPlotData], {
title: 'Admits & Discharges',
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: { varyBarColor: true },
pointLabels: { show: true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
},
highlighter: { show: false }
});
Also, I removed the JSON serialization from my web service, and just returned the object. Hopefully this will help others.
I'm having trouble with autocomplete, usign JSON data.
I'm getting the right response from the callback, but the autocomplete doesn't work properly. For example, when I type "Lon" I get this response:
[{\"value\":\"Dijon, (DIJ)\",\"code\":\"DIJ\"},{\"value\":\"Longview, (GGG)\",\"code\":\"GGG\"},{\"value\":\"Long Island, (HAP)\",\"code\":\"HAP\"},{\"value\":\"Islip, (ISP)\",\"code\":\"ISP\"},{\"value\":\"Long Banga, (LBP)\",\"code\":\"LBP\"},{\"value\":\"Londrina, (LDB)\",\"code\":\"LDB\"},{\"value\":\"Londonderry, (LDY)\",\"code\":\"LDY\"},{\"value\":\"Long Beach, (LGB)\",\"code\":\"LGB\"},{\"value\":\"Long Lellang, (LGL)\",\"code\":\"LGL\"},{\"value\":\"Long Akah, (LKH)\",\"code\":\"LKH\"},{\"value\":\"Londra, (All airports - LON)\",\"code\":\"LON\"},{\"value\":\" - Londra, Gatwick Arpt (LGW)\",\"code\":\"LGW\"},{\"value\":\" - Londra, London City Arpt (LCY)\",\"code\":\"LCY\"},{\"value\":\" - Londra, Stansted Arpt (STN)\",\"code\":\"STN\"},{\"value\":\" - Londra, London Biggin Hill Arpt (BQH)\",\"code\":\"BQH\"},{\"value\":\" - Londra, Heathrow (LHR)\",\"code\":\"LHR\"}]
But my autocomplete just adds Longview and Long Island.
The tricky thing is that after I keep typing "Lond", the autocomplete works perfect, I delete the "d", the autocomplete works perfect, it completes all the data from above.
Where do I go wrong...?
Here's my code:
$("#destination2").keyup(function(){
var term = $("#destination2").val();
//var query_type = $("#form_type").val();
jQuery.get('http://online.bileteavion.com.ro/q_travel_online_api/misc/hotels.autocomplete.php?query_type=flight&term='+term, function(data) {
data = eval('['+data.responseText.split('[')[1].split(']')[0]+']');
var source = $.map(data, function(item) {
return {
label: item.value,
value: item.value,
id: item.id,
iata: item.iata
}
});
$("#destination2").autocomplete({
source: source,
minLength: 3,
search: function(event, ui) {
$('#loading-spinner').show();
},
change: function(event, ui) {
//console.log(ui.item);
if( !ui.item ) {
$(this).val("");
$("input[name='cityId']").val("");
$("input[name='destinationIataCode']").val("");
$("input[name='destination']").val("");
}
},
open: function() {
$('#loading-spinner').hide();
},
select: function(event, ui) {
$("input[name='cityId']").val(ui.item.id);
$("input[name='destinationIataCode']").val(ui.item.iata);
$("input[name='destination']").val(ui.item.value);
$(this).blur();
}
});
}
);
});
jquery.autocomplete is not a function to call every single time you want to display the autocomplete dialog.
You should call jquery.autocomplete only once during initializion, to equip your input field with a full mechanism which allows autocompleting - and which will take care of the "keyup" event.
To achieve what you need, you should use a callback with the source option.
Here is how :
Instead of :
$("#destination2").keyup(function(){
...
jquery.get(<url>, function(data){
var source = ...
$("#destination2").autocomplete({
source: source
minLength: ...
search: ...
open: ...
select: ...
})
})
})
You should write :
$("#destination2").autocomplete({
source: function(request, response){
//request is an obj containing infos on what is typed
//response is a callback, which should be called if you want to display hints
jQuery.get(url + request.term, function(data){
var source = ...
response(source);
})
}
minLength: ...
search: ...
open: ...
select: ...
})
You should check the Remote JSONP datasource from the docs.
I use this in my site. Works quite well.
$("#id").autocomplete({
source: function (request, response) {
$.ajax({
url: 'http://online.bileteavion.com.ro/q_travel_online_api/misc/hotels.autocomplete.php',
dataType: "json",
data: {
//values to pass to server. in your case: query_type & term
term: request.term,
query_type: 'flight'
},
success: function (data) {
response($.map(eval(data), function (item) {
return {
//map values as you previously did
label: item.value,
value: item.value,
id: item.id,
iata: item.iata
}
})
);
}
})
},
minLength: 3,
search: function(event, ui) {
$('#loading-spinner').show();
},
change: function(event, ui) {
//console.log(ui.item);
if( !ui.item ) {
$(this).val("");
$("input[name='cityId']").val("");
$("input[name='destinationIataCode']").val("");
$("input[name='destination']").val("");
}
},
open: function() {
$('#loading-spinner').hide();
},
select: function(event, ui) {
$("input[name='cityId']").val(ui.item.id);
$("input[name='destinationIataCode']").val(ui.item.iata);
$("input[name='destination']").val(ui.item.value);
$(this).blur();
}
});
I'm trying to build a tree from json data, this data are loaded on demand from php files. My problem is that i can't find a way to get to lvl 3 ;). Here is my code:
$(document).ready(function()
{
//Get the screen height and width
var Height = $(document).height()/2;
var Width = $(window).width()/2;
$("#div1").hide();
$("#div2").hide('slow');
$.ajax(
{
type: 'post',
async: true,
url: "getparents.php",
data: {'id' : 12200},
dataType: "json",
cache: false,
beforeSend: function ()
{
//Show the Loading GIF at centered position
$('#loading').css({'top': Height, 'left': Width}).show();
},
success: function(json_data)
{
$("#div1").empty().show();
$('<ul class="parentContainer"></ul>').appendTo("#div1");
$.each(json_data, function(key, object)
{
$('<li id="node">'+object.name+'</li>').data('id', object.id).appendTo(".parentContainer");
if (object.childbool == true)
{
$('li:last').addClass('childfull')
}
});
},
error: function ()
{
$('#loading').hide();
alert('Something Went Wrong with the Loading please hit back in a minute');
},
complete: function ()
{
$('#loading').hide();
}
});
function getChild(id, node)
{
$.ajax(
{
type: 'post',
async: true,
url: "getchilds.php",
data: {'id' : id},
dataType: "json",
cache: false,
beforeSend: function ()
{
$('#loading').show();
},
success: function(json_data)
{
$('<ul class="childContainer"></ul>').appendTo(node);
$.each(json_data, function(key, object)
{
$('<li id="node">'+object.name+'</li>').data('id', object.id).appendTo(".childContainer");
if (object.childbool == true)
{
$('li:last').addClass('childfull')
}
});
},
error: function ()
{
$('#loading').hide();
alert('Something Went Wrong with the Loading please hit back in a minute');
},
complete: function()
{
$('#loading').hide();
}
});
}
$("li.childfull, li.openchildfull").live('click',function()
{
if ($('li.childfull'))
{
var node = $(this);
var id= $(this).data('id');
$(node).html(getChild(id, node));
$(node).removeClass().addClass('openchildfull');
}
else
{
$(node).removeClass().addClass('childfull');
$(node).children().remove();
}
});
});
I think .live is killing me. I get my parents on load; when I click on one I get its children ALL pretty and well, but when I click on a child to get its children I get a very funny behavior. I get its children correctly indented but with no class="childfull" and I get an other copy of them not properly indented but with correct class.. I don't know what is going wrong... Any ideas/corrections are welcome.
P.S: You don't want me to describe to you what happens when I click on the messed up 3rd lvl childfull :P.
Instead of going through the headache of building your own tree, have a look at the jstree plugin. You can pass different formats to it, including json. It allows for complete customization and allows infinite(possible :p) child levels.