i have a jquery-datepicker on my page :
<div id="COICalendar" class="datepicker ll-skin-vigo"></div>
The script looks as follows :
$("#COICalendar").datepicker();
This way I always see the complete month.
Now how can I capture the "onselectedmonthchange"-event (if that exists), in my codebehind file?
The reason I need to do that is because I want to several dates to get a specific color. And those dates come from a database.
Additionally I have several of the calendars on the same page, and I want them all to change to the same month when I change the month on one of those calendars.
You can try using beforeShowDay event callback:
// css
.highlightedDate {
/* highlight styles */
}
// javascript
function paintDatepicker(specialDates) {
$("#" + dateFieldId).datepicker({
beforeShowDay : function(calDate) {
/* This callback function will be invoked before painting each
* date.
* Perform required business validations here and then check
* if the conditions are met.
* You may access 'specialDates' here.
*/
if (condition) {
return [true, "highlightedDate", calDate];
}
}
});
}
Related
i'm using fullcalendar in a web application i"m building.
i load my events with events function and ajax.
here is my code:
var ajaxData;
var eventsJsonArray;
var json_backgrundColor;
var json_iconstring;
//alert('Hello! 1!');
$(document).ready(function () {
$('#calendar').fullCalendar({
header: {
left: 'prev',
center: 'title',
right: 'next,month,agendaWeek,agendaDay'
},
//custom events function to be called every time the view changes
events: function (start, end, timezone, callback) {
var mStart = start.format('M')
var yStart = start.format('YYYY')
$.ajax({
url: '$getMonthDataUrl',
type: 'GET',
data: {
startDate: start.format(),
endDate: end.format()
},
error: function () {
alert('there was an error while fetching events!');
},
success: function (data) {
alert('nice!!');
ajaxData = data;
json_iconstring = ajaxData['iconString'];
json_backgrundColor = ajaxData['Calendar_cell_background_color'];
eventsJsonArray = ajaxData['all_Events_For_The_Month'];
callback(eventsJsonArray); //pass the event data to fullCalendar via the supplied callback function
}
});
},
fixedWeekCount: false,
showNonCurrentDates: false,
dayRender: function (date, cell, view) {
console.log(json_backgrundColor);//this brings eror because json_backgrundColor is undefined
var cellDate = date.format('D');
if (date.format('M') == view.start.format('M')) //cheacking is this day is part of the currrent month (and not prev/next month)
{
alert(cellDate);
cell.css('background-color', json_backgrundColor[cellDate]);//this brings eror because json_backgrundColor is undefined
}
},
})
});
when i load my events via ajax i'm also getting the information about which background color each cell should get. i can only get this info via the events ajax request.
the problem is that when the dayRender is running, i still don't have the background color data. (json_backgrundColor is undefined).
is there a way that dayRender will run after the events calendar will stop running? or any other code that will fix my problem.
many thanks!!
Your problem is that the "dayRender" callback runs after the view is changed (changing the date using prev/next counts as changing the view, for this purpose), but before the events for the new view have been downloaded and rendered. That's why your json_backgrundColor array is undefined.
Since you mentioned that the colour to be used depends on the exact nature of the events currently scheduled for that specific day, we need to find something that we can run after all the events, and this colour data, have been downloaded.
Inspecting the HTML, we can see that the table cells used to draw each day all have the CSS class "fc-day" applied. They also have a data-date property containing the day that they relate to. Finally, days that are disabled (outside the main month, due to you setting showNonCurrentDates:false) have an extra class of "fc-disabled-day" applied. We can use these pieces of information to identify the cells we want to change, without having to use the dayRender callback.
The eventAfterAllRender callback runs once when all the events have been rendered. Therefore this seems like a good place to alter the background colours of the cells:
eventAfterAllRender(function(view) {
//loop through each non-disabled day cell
$('.fc-day:not(.fc-disabled-day)').each(function(index, element) {
//set the background colour of the cell from the json_backgroundColor arrray, based on the day number taken from the cell's "data-date" attribute.
$(this).css('background-color', json_backgroundColor[moment($(this).data("date")).format("D")]);
});
}
Note that I have renamed json_backgrundColor to json_backgroundColor to correct the spelling error.
N.B. This is brittle in the sense that it relies on the class names that fullCalendar uses internally to represent the day cells. If fullCalendar decides to do this differently in a future release, it will break (whereas if we were able to use the fullCalendar API via the designated callbacks, they would likely maintain consistency despite internal changes, or at least document any change). But it's pretty key to the Month view, so realistically it's not likely to change any time soon - you would just have to remember to test it if you update your fullCalendar version.
if anyone still wondering you can use dateSet option like
datesSet: event => {
var from = moment(event.start).format('YYYY-MM-DD');
var to = moment(event.end).format('YYYY-MM-DD');
dateStatus = getEachDateStatus(from, to);
//{'2022-11-10' : 'fullbooked', '2022-11-09' : 'halfBooked'};
Object.keys(dateStatus).forEach(key => {
$('td[data-date="'+key+'"]').addClass(dateStatus[key]);
});
},
Instead of relying on dayRender, you should create background color events based on your ajax:
events = [
...
{ date: date
color: ...
rendering: 'background'
className: 'my-class'
}]
You can transform events using css any way you like, with or without the rendering: 'background' option.
I am trying to disable view picker on account lookup in 2016.
The code works fine I mean I am not getting any error but the code not able to find the particular DIV of "parentaccountid".
Where as I can see it in Elements:
But it's returns {null} when the code try to get the elements of DIV - document.getElementByid("parentaccountid");
My code runs on load of opportunity page.
Even at this step I can see the particular DIV element- id: parentaccountid
Where as I still get {null} value:
Where as in 2013 I have seen it working pretty fine.
Sorry I don't have data to share here but it works fine.
Here is the code below:
function DisablePick()
{
VULoader();
//call this function from OnLoad handler
function VULoader(){
var myLookup1;
alert("Hello..I am Here");
var fetch = "<fetch mapping='logical'>"
+"<entity name='account'>"
+"<attribute name='name'/>"
+"<filter type='and'>"
+"<condition attribute='name' operator='eq' value='Blue Yonder Airlines (sample)' />"
+"</filter>"
+"</link-entity>"
+"</entity>"
+"</fetch>";
myLookup1 = new XrmLookupField("parentaccountid");
myLookup1.AddLockedView(
//sViewId
myLookup1.NewGuid() ,
//sEntityName
"account",
//sViewDisplayName
"My Locked Custom View",
//sFilterXml
fetch,
//sFilterLayout
layout(1, "name", "accountid")
.column("name", 200)
.toString()
);
}
function XrmLookupField(sId) {
var xlf = this;
//control instance
xlf.Ctl = Xrm.Page.getControl(sId);
//dom instance
xlf.Dom = document.getElementById(sId);
//jquery instance
xlf.$ = $(xlf.Dom);
/* 2013 addition --- Inline Control instance --- */
xlf.$i = $("#" + sId + "_i");
//use that to disable the view picker
xlf.DisableViewPicker = function () {
/* 2013 addition --- The attribute capitalization changed */
xlf.SetParameter("disableviewpicker", "1");
}
//use that to enable the view picker
xlf.EnableViewPicker = function () {
/* 2013 addition --- The attribute capitalization changed */
xlf.SetParameter("disableviewpicker", "0");
}
//set undocumented attributes
xlf.SetParameter = function (sName, vValue) {
xlf.$.attr(sName, vValue);
/* 2013 addition --- Also change the inline contorl value */
xlf.$i.attr(sName, vValue);
}
//add locked view
xlf.AddLockedView = function (sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout) {
//first enable the view picker
xlf.EnableViewPicker();
//add the custom view (last parameter set the view as default)
xlf.Ctl.addCustomView(sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout, true);
//lock the view picker
xlf.DisableViewPicker();
}
//create new guid
xlf.NewGuid = function () {
var d = new Date().getTime();
var guid = '{xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx}'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
});
return guid;
}
}
}
Few points to mention:
I am calling DisablePicker method on load of an opportunity page.
Yes, I have already checked whether any duplicate id is there or not but I didn't find any.
I tried to run this method on load of Account field as well but nope no response.
If I change the property disableviewpicker value from 0 to 1 in DIV itself manually from browser after page gets loaded & open the lookup then it will take the effect of the changed value.
Really I am getting no clue why it's behaving this manner, I just need to know where exactly I am going wrong or it's a product bug but I don't think it is. As its a very basic behavior.
PS: For my non MS CRM friends I cannot change the DIV or anything except my JavaScript code.
Your form code executes in a frame that is separate from the actual CRM form; it runs in the ClientApiWrapper.aspx page. Therefore, to access the form element you want to modify from your form script, you form code should do parent.document.getElementById instead of document.getElementById.
When you use your browser's dev tools, the default frame that the console executes against is also not the frame that has your form elements, and it's also not the frame that has your form's code. The simplest way to execute against the correct frame is to use the function in your dev tools to switch frames. In Firefox, that button looks like this:
It's easiest to set your frame to the ClientApiWrapper.aspx one, as it provides access to both the libraries loaded on your form as well as the CRM client-side API.
I want a effect like this:
when i typing something in <input>,vue could help me format the string.
eg:when someone typting 20160324... ,this can format like "2016-03-24..." at the same time(so this effect must be show in a same <input>),because my expected is "2016-03-24 15:00:00".
ps:
my <input> are generate dynamic by an object array.i want konw what the right way to write "v-model" on every item.
because of i don't know what the specified <input>,so i cant't watch it by "Vue.$watch".
my data like that below:
data{
form:[
{name:'name',value:'',inputType:'text'},
{name:'sex',value:'',inputType:'radio'},
{name:'age',value:'20',inputType:'text'},
{name:'time',value:'',inputType:'date'},
]
}
Thanks
The first to dynamically generate the form you can see here https://jsfiddle.net/2q3Lt1vr/.
The [type=date] input is rendered as html5 date-picker. So the second example I will change date to text. You can see here https://jsfiddle.net/dgq01f6u/2/.
The format method depends on your own logic. This demo needs you to unfocus when you finish your type.
If you want to update the input filed on real time, you may need to use watch like
watch: {
form: {
deep: true,
handler: function() {
this.form.forEach(function(field) {
if (field.inputType === 'date') {
// do your format
}
});
}
}
}
I'm working with http://arshaw.com/fullcalendar/ and I would like to dynamically filter the events shown based on various checkboxes on the page. I am using an ajax source (with filters passed as parameters) to gather data.
The problem I am running into is once I load the calendar, I cannot, for the life of me (or stackoverflow searches) figure out how to update the parameters. It seems once the calendar is loaded, those parameters are "baked" and cannot be changed.
I have tried every combination of addEventSource, removeEventSources, removeEvents, refetchEvents, etc (as recommended here: rerenderEvents / refetchEvents problem), with still no luck.
My current solution is to re-initiate the entire .fullCalendar every time a filter is updated-- this is leading to tons of issues as well and really isn't an elegant solution.
Any ideas on a simpler way to do this? Refetching your source with updated parameters each time should be automatic. I really do appreciate your help.
In my code i do like that :
I have an array with the calendars id to display and i update it when the user check or uncheck the checkbox.
In fullCalendar initialization I retrieve all events and i filter them with this function :
function fetchEvent( calendars, events) {
function eventCorrespond (element, index, array) {
return $.inArray(element.calendarid, calendars) > -1;
}
return events.filter(eventCorrespond);
}
$('#calendar').fullCalendar({
events: function(start, end, callback) {
//fetch events for date range on the server and retrieve an events array
//update calendars, your array of calendarsId
//return a filtered events array
callback(fetchEvent(calendars , events));
}
});
and when the user check or uncheck a checkbox i do :
$('#calendar').fullCalendar('refetchEvents');
The solution that works for me is:
$('#calendar').fullCalendar('removeEventSource', 'JsonResponse.ashx?technicans=' + technicians);
technicians = new_technicians_value;
$('#calendar').fullCalendar('addEventSource', 'JsonResponse.ashx?technicans=' + technicians);
After "addEventSource" events will be immediately fetched from the new source.
full answer here https://stackoverflow.com/a/36361544/5833265
I am working with a Jquery time picker from http://labs.perifer.se/timedatepicker/
In the view I have this time picker control.
$("#startTime").timePicker({
startTime: "09.00",
endTime: new Date(0, 0, 0, 19, 0, 0),
show24Hours: false,
separator: '.',
step: 30
});
If a particular time (say 11:00 AM) is picked previously (and saved in db) that particular option should be disabled and not available for subsequent selections. In a MVC controller, via a service layer, I am getting a 'list' of all previously picked times.
public ActionResult DisableTimes(param1, param2)
{
List<string> listTimes = Webservice(param1,param2);
//getting previously saved times - above line
return Json(listTimes, JsonRequestBehavior.AllowGet);
}
I am making an ajax call in a java script function like this.. that passes the parameters to MVC controller and returns back the list of times.
$.ajax({
"url": "/ControllerName/DisableTimes/",
"type": "get",
"dataType": "json",
"data": { param1: $("#paramval1").val(), param2: $("#paramvalue2").val() },
"success": function (listTimes) {
//Code here - use the listTimes values and disable the
//appropriate timepicker drop down choices.
}
});
How can I make use of the list of times "listTimes" I am getting from controller to disable the Jquery Timepicker choices?
You should just be able to remove the li's from available options in the following manner:
$(listTimes).each(function() {
$('.time-picker').find('li:contains("' + this + '")').remove();
});
Edit:
It will be a little bit harder if you have multiple time pickers on a page though. You should be able to add the :first selector to only get the first time picker.
$('.time-picker:first').find('li:contains("' + this + '")').remove();
Live DEMO
apparently this datepicker plugin doesn't give you the possibility to remove his behavior.
But I do believe that you could remove the element from the document.
and re-add it again.
using :
http://api.jquery.com/remove/
and
http://api.jquery.com/add/
Or you could have two element for each time, show/hide what you need or using :
http://api.jquery.com/hide/
and
http://api.jquery.com/show/
it doesn't seem that the plugin offers that functionality by default. I would change these lines in the plugin code slightly (the bits where it appends to the list)
// Build the list
for(var i = 0; i < times.length; i++) {
$tpList.append("<li>" + times[i] + "</li>");
}
to something that adds some identifier to each li:
for(var i = 0; i < times.length; i++) {
$tpList.append("<li class='"+times[i]+'">" + times[i] + "</li>");
}`
just to make selecting those li elements easier then in your success handler, do something like:
"success": function (listTimes) {
$(listTimes).each(function(i,item){
$('li.'+item).remove();
});
//or may be if you are just getting an array of strings from the webservice then something like this will be enough: $('.'+listTimes.join(',.')).remove();
}
and also put the timepicker plugin call $("#startTime").timePicker inside the ajax success callback so that there is no race condition as the ajax callback will happen after the plugin initialization probably.
Another alternative is just to handle $('#startTime').change and check if the time is not allowed and display an error to the user.