Input type date not showing value - html

I've got a project in Symfony2 (v. 2.2.11) in which I've got a calendar (fullCalendar) and when a user clicks in a day I open a overlay with a form and my start and end date got the selected day as value (format yyyy-MM-dd). If I inspect the element there's a value with the correct date but is not showing in input box, only shows when I click a date (I'm using jquery date chooser) the value appears in the input box (the new one).
This is my FormType code for start and end date:
->add('startDate','date',array(
'label'=>'ueb_crossfit_class.form.event.labels.startDate',
'widget' => 'single_text',
'format' => "yyyy-MM-dd",
'attr' => array('class' => "input-date datepicker")
))
->add('endDate','date',array(
'required' => false,
'label'=>'ueb_crossfit_class.form.event.labels.endDate',
'widget' => 'single_text',
'format' => "yyyy-MM-dd",
'attr' => array('class' => "input-date datepicker")
))
This is the generated input (for start date):
<input id="ueb_crossfiterz_bundle_classbundle_eventtype_startDate" class="input-date datepicker hasDatepicker" type="date" value="2013-12-27" required="required" name="ueb_crossfiterz_bundle_classbundle_eventtype[startDate]">
I've already tested with Firefox and Chrome and both doesn't show the value but only Firefox show that red line in input (as appear in image).
[UPDATE]
As asked in comments here's my js code for initializing fullCalendar:
$(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar-holder').fullCalendar({
header: {
left: 'prev, next',
center: 'title',
right: 'month,agendaWeek,agendaDay,'
},
lazyFetching:true,
selectable: true,
timeFormat: {
// for agendaWeek and agendaDay
agenda: 'HH:mm{ - HH:mm }', // 5:00 - 6:30
// for all other views
'': 'HH:mm{ - HH:mm }' // 7p
},
eventSources: [
{
url: Routing.generate('ueb_class_getEvents'),
type: 'POST',
error: function() {
//alert('There was an error while fetching Google Calendar!');
}
}
],
eventClick: function(event) {
clickEvent(event);
return false;
},
select: function(start, end, allDay){
selectEvent(start, end, allDay);
}
});
});

Related

FullCalendar not fetching Events from Feed of DB Query (Laravel)

My event feed does only work when I hardcode the events in my EventController. Once I get them from database query the events are not displayed though the first event is the exact same I used in the hardcoded event.
Works (Calendar shows event):
public function eventFeed(Request $request)
{
$events = array(
[
"id" => 1,
"resourceId" => '1115',
"title" => 'Wartung Steuerung',
"start" => '2020-06-11 00:20:23',
"end" => '2020-06-28 21:21:30',
]
);
return json_encode($events);
}
From the calendar view I have a control Ajax call that fetches the same feed as FullCalendar. The received feed is
[{"id":1,"resourceId":"1115","title":"Wartung Steuerung","start":"2020-06-11 00:20:23","end":"2020-06-28 21:21:30"}]
Does not work (Calendar stays empty):
public function eventFeed(Request $request)
{
$start = Carbon::create($request->input('start'));
$end = Carbon::create($request->input('end'));
$events = DB::table('toolplanview')->select('id','resourceId','title','start','end')
->whereDate('start', '>=', $start)->whereDate('end', '<=', $end)->get();
return json_encode($events);
}
The feed from the DB query is:
[{"id":1,"resourceId":"1115","title":"Wartung Steuerung","start":"2020-06-11 00:20:23","end":"2020-06-28 21:21:30"},{"id":2,"resourceId":"1157","title":"Werkstatt","start":"2020-06-12 09:09:41","end":"2020-06-24 03:45:59"},{"id":3,"resourceId":"1136","title":"Neue Toranlage","start":"2020-06-10 20:29:44","end":"2020-06-23 04:26:38"},{"id":4,"resourceId":"1138","title":"Neue Toranlage","start":"2020-06-10 03:23:12","end":"2020-06-28 11:20:36"}]
I dont see why this feed would not work. My calendar:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
locale: 'de',
plugins: [ 'interaction', 'resourceTimeline' ],
defaultView: 'resourceTimelineWeek',
editable: true,
titleFormat: { year: 'numeric', month: '2-digit', day: '2-digit' },
header: {
right: 'today prev,next'
},
slotLabelFormat: [
{ month: 'long', year: 'numeric' }, // top level of text
{ weekday: 'short', day: '2-digit' } // lower level of text
],
resources: 'http://localhost/matpro/public/resource-feed',
events: 'http://localhost/matpro/public/event-feed',
});
calendar.render();
});
I found the reason for this behaviour, the issue is the where clause of my DB query:
$events = DB::table('events')->select('id','resourceId','title','start','end')->get();
->whereDate('start', '>=', $start)->whereDate('end', '<=', $end)->get();
When calender e.g. displays a week from 01.06. to 08.06 and one of my (generally longer) events starts on 30.05. and ends on 05.06. this event won't be displayed due to the where clauses in my query. The example dates I picked for testing accidentally overlapped with the calender start or end and therefore did not show up.

Ajax response full calendar view page issue

Here is the relevant code:
VIEW PAGE:
<script type="text/javascript">
$(document).on("click", ".calendarview", function () {
var roomid = $(this).data('id');
//alert(roomid);exit;
$('#calendar_view').fullCalendar({
//events: [
// {
// title: 'All Day Event',
// start: roomid
// }
// ]
events: {
url: base_url+'home/calview',
dataType: 'json',
data: {roomid: roomid},
type: 'POST', // Send post data
error: function() {
alert('There was an error while fetching events.');
}
}
});
});
</script>
IN CONTROLLER
function calview()
{
$room_id =$this->input->post('roomid');
$events=$this->Home_model->find_room_availability($room_id);
$data_events = array();
foreach($events as $r) {
$data_events[] = array(
//"title" => $r->available,
"description" => 'available',
"start" => $r->dt);
}
echo json_encode(array("events" => $data_events));
exit();
}
MODEL:
function find_room_availability($room_id){
$result = $this->db->query("SELECT x.dt , r.room_cnt - COALESCE(SUM(`booking_cnt`),0) available FROM calendar_table x LEFT JOIN bookinglist y ON x.dt >= y.`date_from` AND x.dt < y.`date_to` LEFT JOIN rooms r ON r.id=$room_id WHERE x.dt BETWEEN now() - interval 3 month AND now() + interval 5 month GROUP BY dt ");
//echo $this->db->last_query();
//exit;
return $result->result();
}
Ajax response is like
[[{"title":"10","start":"2017-04-26"},{"title":"10","start":"2017-04-27"},
{"title":"10","start":"2017-04-28"},{"title":"10","start":"2017-04-29"},
{"title":"10","start":"2017-04-30"},{"title":"10","start":"2017-05-01"},
{"title":"10","start":"2017-05-02"},{"title":"10","start":"2017-05-03"},
{"title":"10","start":"2017-05-04"},{"title":"10","start":"2017-05-05"},
{"title":"10","start":"2017-05-06"},{"title":"10","start":"2017-05-07"},
{"title":"10","start":"2017-05-08"},{"title":"10","start":"2017-05-09"},
{"title":"10","start":"2017-05-10"},{"title":"10","start":"2017-05-11"},
{"title":"10","start":"2017-05-12"},{"title":"10","start":"2017-05-13"},
{"title":"10","start":"2017-05-14"},{"title":"10","start":"2017-05-15"},
{"title":"10","start":"2017-05-16"},{"title":"10","start":"2017-05-17"},}]]
can anyone please help me to find a solution
Your JSON is an array within an array, which fullCalendar cannot understand. It expects a single array of events.
This is the problem:
echo json_encode(array("events" => $data_events));
Since $data_events is already an array, there's no need to wrap it inside another one.
echo json_encode($data_events);
should be sufficient, and produce the format that fullCalendar is expecting.
N.B. There also appears to be a stray extra bracket at the end of your JSON sample: ,}]] but I'm assuming this is just a typo.

Persist State In Kendo MVC Grid With Custom Command Columns?

Having issues persisting state in mvc grid when using custom command columns. Here is the grid's wrapper
#(Html.Kendo().Grid < Weighmaster_Web.Data.Entity.Destination > ()
.Name("grid")
.Columns(columns => {
columns.Bound(c => c.Description);
columns.Bound(c => c.CODE);
columns.Command(c => {
if (bUpdate) c.Custom("Edit").Click("editItem");
if (bDelete) c.Custom("Delete").Click("deleteItem");
}).Width(175);
})
.Scrollable()
.Groupable()
.Sortable()
.ToolBar(toolbar => {
if (bCreate) {
toolbar.Create().HtmlAttributes(new {
id = "addDestination"
}).Text("Add Destination");
}
})
.ToolBar(t => t.Excel())
.Excel(excel => excel
.FileName("Destinations.xlsx")
.Filterable(true)
.AllPages(true)
.ProxyURL(Url.Action("Excel_Export_Save", "MaterialTransaction"))
)
.Filterable(filterable => filterable.Extra(false))
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Read(read => read.Action("DestinationIndex", "Destination").Type(HttpVerbs.Post))
.Model(model => model.Id(p => p.Id))
.PageSize(20)
.Create(update => update.Action("DestinationSave", "Destination").Type(HttpVerbs.Post)))
)
Here i define a click event handler in the wrapper for both edit and delete buttons. i am using custom commands so that i may define custom edit template.
When you look at the actual jquery for this wrapper , i can see the event handler defined.
Then when you leave the page , this code is ran to save the grid's state in a cookie :
$(window).unload(function () {
var grid = $("#grid").data("kendoGrid");
var dataSource = grid.dataSource;
var state = {
columns: grid.columns,
page: dataSource.page(),
pageSize: dataSource.pageSize(),
sort: dataSource.sort(),
filter: dataSource.filter(),
group: dataSource.group()
};
$.cookie(username + "DestinationGridState", JSON.stringify(state), { expires: 365 });
})
The grid's state is read from cookie in $(document).ready like this :
$(document).ready(function () {
var grid = $("#grid").data("kendoGrid");
var toolbar = $("#grid").find(".k-grid-toolbar").html();
var state = $.cookie(username + "DestinationGridState");
if (state) {
state = JSON.parse(state);
var options = grid.options;
options.columns = state.columns;
options.dataSource.page = state.page;
options.dataSource.pageSize = state.pageSize;
options.dataSource.sort = state.sort;
options.dataSource.filter = state.filter;
options.dataSource.group = state.group;
if (grid) {
grid.destroy();
//grid.wrapper.html("");
}
$("#grid").empty().kendoGrid(options).find(".k-grid-toolbar").html(toolbar);
}
});
After the grid's state is read from the cookie, no click event handler is defined for the custom edit command button. So , i guess my question is; How do i correctly save the state of the grid so that my custom command buttons will retain their event handlers?
As mentioned in the kendo documentation:
JSON.stringify() cannot serialize function references (e.g. event
handlers), so if stringification is used for the retrieved Grid state,
all configuration fields, which represent function references, will be
lost.
I once had the same issue, when I was trying to save the filters values in session. I was doing just like you, but then I realized that I didn't need to restore the columns state. If you remove the row options.columns = state.columns;
the custom command will work just as expected.
Hope it helps.
I had a similar problem. After loading the settings my custom delete button stopped working. This was the solution that I came up with:
Save the original grid options. After parsing the saved settings, restore the original values, in this case the column where my delete buttons was placed.
Hope this helps.
$("#Grid").on("click",
".loadsetting",
function(e) {
var grid = $("#Grid").data("kendoGrid");
var originalOptions = grid.options; // Save original options
e.preventDefault();
var options = localStorage["msettings"];
if (options) {
var parsedOptions = JSON.parse(options);
parsedOptions.toolbar = [
{
template: $("#toolbarTemplate").html()
}
];
// Restore values
parsedOptions.columns[30] = originalOptions.columns[30];
grid.setOptions(parsedOptions);
}
});

kendo grid export gives Input string was not in a correct format error

When im trying to export kendo resault into pdf i get this error "Input string was not in a correct format."
here is my code :
#(Html.Kendo().Grid((IEnumerable<A.Models.MyViewModel>)ViewBag.myviewmodelbag) //Bind the grid to ViewBag.Products
.Name("List")
.Columns(columns =>
{
columns.Bound(myviewmodelbag => myviewmodelbag.BaseData.Type);
columns.Bound(myviewmodelbag => myviewmodelbag.BaseData.Title);
})
.Pageable() // Enable paging
.Sortable() // Enable sorting
.Groupable()
.Filterable()
.Events(ev => ev.DataBound("onDataBound"))
.ToolBar(toolBar =>
toolBar.Custom()
.Text("Export To PDF")
.HtmlAttributes(new { id = "export" })
.Url(Url.Action("Export", "MyViewModel", new { page = 1, pageSize = "~", filter = "~", sort = "~" }))
)
<script type="text/javascript">
function onDataBound(e) {
var grid = $('#List').data('kendoGrid');
// ask the parameterMap to create the request object for you
var requestObject = (new kendo.data.transports["aspnetmvc-server"]({ prefix: "" }))
.options.parameterMap({
page: grid.dataSource.page(),
sort: grid.dataSource.sort(),
filter: grid.dataSource.filter()
});
// Get the export link as jQuery object
var $exportLink = $('#export');
// Get its 'href' attribute - the URL where it would navigate to
var href = $exportLink.attr('href');
// Update the 'page' parameter with the grid's current page
href = href.replace(/page=([^&]*)/, 'page=' + requestObject.page || '~');
// Update the 'sort' parameter with the grid's current sort descriptor
href = href.replace(/sort=([^&]*)/, 'sort=' + requestObject.sort || '~');
// Update the 'pageSize' parameter with the grid's current pageSize
href = href.replace(/pageSize=([^&]*)/, 'pageSize=' + grid.dataSource._pageSize);
//update filter descriptor with the filters applied
href = href.replace(/filter=([^&]*)/, 'filter=' + (requestObject.filter || '~'));
// Update the 'href' attribute
$exportLink.attr('href', href);
}
</script>
and my controller is like this :
public FileResult Export([DataSourceRequest]DataSourceRequest request)
{
IEnumerable products = db.AA.ToDataSourceResult(request).Data;
now the problem is if i use exatcly as above i get the error but if hardcode the value like this:
.Url(Url.Action("Export", "MyViewModel", new { page = 1, pageSize = "", filter = "", sort = "" }))
it works without error but the controller only get the page an other value will be null.
also i tried to add "grid_Page , ... " to all of parameter but none works
Ok my bad , i fixed it !
since im using server side to populate the grid , the js event part cant be called :
function onDataBound(e) {
var grid = $('#List').data('kendoGrid');
and after i changed to this :
$(document).ready(function () {
var grid = $('#List').data('kendoGrid');
and removed this line :
.Events(ev => ev.DataBound("onDataBound"))
now it works fine.

Proper JSON date time syntax for fullcalendar

need some help for the proper syntax for display the event times in agenda view. The events only shows up under all day despite having allDay set to false.
My json.html page looks like this:
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventSources: [
{
url: 'json-events.php', // use the `url` property
color: 'yellow', // an option!
textColor: 'black', // an option!
editable: false
},
// Dont forget coma - but not on the last one
{
url: 'other-events.php', // use the `url` property
color: 'red',
textColor: 'black',
editable: 'false',
allDay: 'false'
}
// any other sources...
]
});
});
One of the php pages looks like this:
<?php
echo json_encode(array(
array(
'id' => 112,
'title' => "What is this?",
'start' => "2011-10-11T13:00:00",
'end' => "2011-10-12T15:00:00",
'allDay' => "false"
),
));
?>
How do I get the events to display in the week and day agend view with the proper time (instead of being listed under the "all day" section)?
Thanks,
Extreme Newbie
After tweaking the code, I got it to work by removing the "" around false. The php page should look like this:
'allDay' => false
:)
You need to take the quotation off of "false". "false" is a string, and false is the correct "bool" false.
Also, your json call should have a query such as...
$sql = mysql_query("query") or die(mysql_error());
Followed by a while statement to retrieve the information...
while($arr = mysql_fetch_array($sql)){
$array_content[] = $arr;
}
Then encode...
echo json_encode($array_content);
This will render whatever data you have in the database.
A simple if statement within the while statement will change the string to a bool like so...
if($arr['allDay'] === "true"){
$arr['allDay'] = true;
} else {
$arr['allDay'] = false;
}
}
Hope this helps!