Set date from model, not default by datetimepicker - asp.net-mvc

Have a good day. I'm searching the way to set date from edit view in my app and only shows the current date.
I'm using bootstrap datetimepicker like this:
$('.datepicker').datetimepicker(
{
format: 'DD/MM/YYYY',
locale: 'es',
icons: {
time: "fas fa-clock",
date: "fas fa-calendar-alt",
up: "fas fa-arrow-up",
down: "fas fa-arrow-down",
previous: "fas fa-chevron-left",
next: "fas fa-chevron-right"
},
defaultDate: null,
daysOfWeekDisabled: [0, 6]
});
and in my form I've implemented as:
#Html.EditorFor(model => model.ApplyDate, new { htmlAttributes = new { #class = "form-control datepicker", placeholder = "dd/mm/yyyy", tabindex = "5", maxlength = "10", required = "", #Value = Model.ApplyDate } })
but not getting any good results. Only current date is set.
Thanks.

I've just realized that my problem setting default date was cause I've used the disabled dates property:
daysOfWeekDisabled: [0, 6]
Once I've take off that part, my problem was solved. Hope to help someone

Related

need help: editor and numbers asp.net

I have an editor field in asp.net which needs to be integer input only between 1 and the size of a list. Atm i got this as code
#Html.Editor("Prioriteit" + item, new { htmlAttributes = new { #type = "number", min = "0",step = "1", value = "0" } })
this isn't to the maximum of the list, I know this. However when i open the page i can still add text.
View with text in editor
Someone can help me out?
thanks in advance
Changed the code for the sake of someone linking it to another question
code
#Html.TextBox("Prioriteit" + item,null, new { htmlAttributes = new { #type = "number", min = "0",step = "1", value = "0" } })
still the same
`
You can also do the following:
<input type="number" min="0" step="1" value="0" name="Prioriteit#item" />
Try this:
#Html.TextBox("Prioriteit" + item, "0", new { #type="number", min = "0", step = "1" })

Fullcalendar timezone option is ignored

I am fighting with the timezone option of fullCalendar plugin. It doesn't matter what I set: none, UTC or a specific location, everything is ignored by the plugin. All given times are shown as UTC+2 (Thats my location). What i do:
First creating some events according following code:
if(!newsCalendarEvent){
var newsCalendarEvent = [];
}
newsCalendarEvent["Event_1"] = {
events: [
{
title: 'my first news',
start: '2015-08-02T17:46:00Z',
end: '2015-08-10T17:46:00Z',
className: 'Event_1'
}
],
color: '',
textColor: ''
}
Then creating the calendar and looping through these events:
newsCalendar = $('#calendar').fullCalendar({
lang: 'de',
buttonIcons: false, // show the prev/next text
weekNumbers: true,
timezone : 'none',
timeFormat: 'H(:mm)'
})
for (var key in newsCalendarEvent) {
if (newsCalendarEvent.hasOwnProperty(key)) {
newsCalendar.fullCalendar( 'addEventSource', newsCalendarEvent[key] )
}
}
Solved. The problem had nothing to do with this plugin. It has been a qustion of timesetting in my php code.

.NET Kendo Scheduler: dynamically change datasource resources

Now i'm using a datasource like this: (with the parameters to filter hard coded)
$(function () {
$("#scheduler").kendoScheduler({
date: new Date(Date.now()),
startTime: new Date(2013, 5, 13, 9, 0, 0, 0),
height: 800,
timezone: "Etc/UTC",
group: {
resources: ["Rooms"]
},
resources: [
{
name:"Rooms",
title: "Room",
field: "RoomID",
dataSource: {
transport:
{
read: { url: "#Html.Raw(Url.Action("Filter_Rooms", "Room", new{
pPar1= true,
pPar2 = false,
pPar3 = true,
}))", dataType: "json" }
}
}
}
As you can see these paramaters are still hard coded and I want to change them whenever the user wants using checkboxes:
<div class="checkbox">
<label>
<input id="chkPar1" type="checkbox"> Parameter 1
</label>
</div>
<div class="checkbox">
<label>
<input id="chkPar2" type="checkbox"> Parameter 2
</label>
</div>
Filter
I thought while using javascript to check if button is clicked and then store checkbox paramaters in global variables and use these in the transport read of the scheduler but it seems you can't use document.getelementbyId here.
Here they suggested Kendo UI Dynamically Change Datasource String (XML) but that doesn't seem to work for me neither..
var dynamicUrl = "Html.Raw(Url.Action('Filter_Rooms', 'Room', new{pFilter = true, pCapacity = 25,pBeamer = true,pTelevision = false}))', dataType: 'json'"
var scheduler = $("#scheduler").data("kendoScheduler");
scheduler.dataSource.transport.options.read.url = dynamicUrl;
So How can I dynamically change these paramaters or update the entire transport read url?
Regards
Try this:
var pFilter = (document.getElementById("someID").value);
var pCapacity = document.getElementById("someID").value;
var pBeamer = document.getElementById("someID").value;
var pTelevision = document.getElementById("someID").value;
var dynamicUrl = "Html.Raw(Url.Action('Filter_Rooms', 'Room', new{pFilter = " + pFilter + ", pCapacity = " + pCapacity + ",pBeamer = " + pBeamer + ",pTelevision = " + pTelevision + "}))', dataType: 'json'"
There could be some type of string format that you could use like in C# but I'm not sure. Hope this works!
Not sure if it's exactly what you're after, but a good frame of reference might be this example project. It very simply shows how to load new content when you change the view. You may be able to adapt it.

Flot won't Plot (Ruby)

I'm playing around with FLOT with Ruby and I'm having a hard time passing the code to javascript; I know my javascript isn't reading the data correctly from Ruby. I need some syntax help.
o={};
o= {'label' => "A", 'data' => #example.collect{|x| [Time.utc(x.date).to_i, x.num]}}
render :text => o.to_json
I have successfully rendered the output as such:
{"label":"A","data":[[1281225600,1.31],[1281225600,1.31],[1281225600,1.25]]}
The HTML outputs this data only.
My javascript is as follows:
var obj = jQuery.parseJSON(text);
var options = {
lines: { show: true },
points: { show: true },
xaxis: { mode: "time", timeformat: "%m/%d/%y", minTickSize: [1, "day"]}
};
var data = obj;
$.plot(placeholder,[data],options);
}
What you are missing is that Ruby puts out timestamps in the Unix format (i.e. seconds since the epoch 1281225600). Flot requires javascript timestamps, which count the milliseconds since the epoch, i.e. 1281225600*1000.
So in your Ruby code, your best bet is to do something like this:
o={};
o= {'label' => "A", 'data' => #example.collect{|x| [Time.utc(x.date).to_i*1000, x.num]}}
render :text => o.to_json
Or if you prefer, you could loop over the obj.data and do the multiplication on the Javascript side:
for (i=0;i<obj.data.length;i++){
obj.data[i] = obj.data[i]*1000;
}
Ok I got it....
Ruby code:
#o={};
#o= {'label' => "A", 'data' => #example.collect{|x| [Time.utc(x.date).to_i, x.num]}}
Java code:
$(function () {
var obj = <%= #o.to_json %>;
var options = {
lines: { show: true },
points: { show: true },
xaxis: { mode: "time", timeformat: "%m/%d/%y", minTickSize: [1, "day"]}
};
var data = obj;
$.plot(placeholder,[data],options);
});

Html Helper with special htmlattributes

Does anyone know how to pass html attributes like "data-date" to the Html.TextBox()??
It is used from the bootstrap datepicker.
Is there a way around it?
#Html.TextBoxFor(p => p.DateFrom, new { #class = "small", type = "date", "data-date"="12-02-2012" })
You have to use underscore instead of '-'.
So what you're after would go something like this:
#Html.TextBoxFor(p => p.DateFrom, new { #class = "small", #type = "date", #data_date="12-02-2012" })
Use:
new Dictionary<string, object> { { "class", "small" }, {"type", "date"} { "data-date", "12-02-2012" } }
instead of:
new { #class = "small", type = "date", "data-date"="12-02-2012" }
I was trying to add the date picker to the Html helper using bootstrap. rudeovski ze bear's answer made it easier.
This is how it worked for me.
#Html.TextBox("startdate", null
, new {#class = "type", #type = "date", #data_date="12-02-2012" })

Resources