disable days in rich faces 4 calendar component - jsf-2

I am using two ric:calendar one for start date and another for end date.
the end date should disable all the previous dates automatically based on the start date selection.
Can it be possible using dayDisableClass?

Regadring the disabledDay way...
take a look at this post: Disable days on rich:Calendar
Also you can use the calendar CalendarDataModel -> CalendarDataModelItem -> isEnabled()
Boolean isEnabled() returns "true" if date is "selectable" on the calendar, the default implementation returns "true"
take a look at the Demo

You could use calendar's attribute dayDisableFunction and define your JavaScript function which would define which days are disabled:
<rich:calendar dayDisableFunction="disablementFunction" ...</rich:calendar>
example JS function:
function disablementFunction(day) {
if (day.isWeekend) return false;
return true;
}

Related

How to show Jquery UI datepicker year and months in extra calendar tables?

My problem is that Jquery UI allows selecting a year or month from dropdown menu only.
How can I modify the default date picker to allow selecting year and month as additional calendar tables for default date picker?
Default view:
How I want to select months -> clicking on a month to show extra calendar:
Desired month functionality:
clickable month label
no dropdowns
when clicking on month label - it should open now calendar where days are replaced with month selection
(screen 2 shows what happens when you click on target area on screen 1)
How I want to select years -> clicking on year to show extra calendar:
Desired year functionality:
clickable year label
no dropdowns
when clicking on year label - it should open now calendar where days are replaced with year selection
(screen 2 shows what happens when you click on target area on screen 1)
As I understand, I need to create a new calendars onclick of "month" or "year" label but I don't have any idea how to make that + how to show months or years in calendar instead of a dropdown.
Due to the dynamic nature of Datepicker, it rebuilds each calendar, there is not a good way to do this "out of the box".
How can I modify the default date picker to allow selecting year and month as additional calendar tables for default date picker?
Here is a basic example of how you could start to set this up. The issue comes in when you then make a selection. The datepicker redraws all the various elements and will remove all the customization.
Example: https://jsfiddle.net/Twisty/v6c9r8pa/56/
JavaScript
$(function() {
var dp = $("#datepicker-1").datepicker({
changeMonth: true,
changeYear: true
});
$("#datepicker-2").datepicker();
$(".ui-datepicker-month", dp).hide();
$("<span>", {
class: "ui-datepicker-month-btn btn"
}).html($(".ui-datepicker-month option:selected", dp).text()).insertAfter($(".ui-datepicker-month", dp));
$(".ui-datepicker-year", dp).hide();
$("<span>", {
class: "ui-datepicker-year-btn btn"
}).html($(".ui-datepicker-year option:selected", dp).text()).insertAfter($(".ui-datepicker-year", dp));
function selectMonth(ev) {
var mObj = $(ev.target);
$(".ui-datepicker-month", dp).val(mObj.data("value")).trigger("change");
$(".ui-datepicker-month-btn", dp).html(mObj.text().trim());
mObj.closest(".ui-datepicker").find(".ui-datepicker-calendar").show();
mObj.closest(".ui-datepicker-month-calendar").remove();
}
function showMonths(trg) {
$(".ui-datepicker-calendar", trg).hide();
var mCal = $("<table>", {
class: "ui-datepicker-month-calendar"
}).insertAfter($(".ui-datepicker-calendar", trg));
var row, cell;
$(".ui-datepicker-month option").each(function(i, o) {
if (i % 4 == 0) {
row = $("<tr>").appendTo(mCal);
}
cell = $("<td>").appendTo(row);
$("<span>", {
class: "ui-widget-header circle btn"
})
.data("value", $(o).val())
.html($(o).text().trim())
.click(selectMonth)
.appendTo(cell);
if ($(o).is(":selected")) {
$("span", cell).addClass("selected");
}
});
}
$(".ui-datepicker-month-btn").click(function() {
console.log("Show Months");
showMonths(dp);
})
});
If you want to get in "under the hood", then take some time to review the following, Widget Factory.
The jQuery UI Widget Factory is an extensible base on which all of jQuery UI's widgets are built. Using the widget factory to build a plugin provides conveniences for state management, as well as conventions for common tasks like exposing plugin methods and changing options after instantiation.
So you could rebuild some of the elements in your own making from inside, so that when you do make a selection, it redraws all the elements as you desire.

Datebox - get the event and validate year, month, and date by entering a value manually

I am using datebox plugin for jquery mobile http://dev.jtsage.com/jQM-DateBox2/unit/datebox.html
Everything works fine.
Here my question is how do i validating the individual year, month, date input fields by entering the numeric values in the specific fields ((ie) keydown/keypress..) without using of plus and minus buttons.
Thanks in advance...
This function checks if the input changed and logs the new date into the console.log:
$("div.ui-grid-b div input.ui-input-text").change(function() {
var parent = $(this).parent().parent();
console.log("date changed to: "
+parent.find("div.ui-block-a input.ui-input-text").val()+":"
+parent.find("div.ui-block-b input.ui-input-text").val()+":"
+parent.find("div.ui-block-c input.ui-input-text").val()
);
});

How to programatically set a date in jquery mobile Datebox plugin 1.1.0

I want to programmatically set date for the input with datebox control, For this i know i can use something like this
$(element).trigger('datebox', {'method':'set', 'value':'dateString'});
but this doesn't seem to update the control(i.e when i open the calendar, it is set to current date and not equal to the value in the input field)
EDIT:
based on JTsage's pointers i overwrote the default dateformat to mm/dd/yyyy, using sth like this.
jQuery.extend(jQuery.mobile.datebox.prototype.options.lang, {
'en': {
dateFormat: '%m/%d/%Y'
}
});
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
useLang: 'en'
});
Then i tried setting the date using sth like this
$(element).trigger('datebox', {'method':'set', value:'07/02/2012'});
but this date is not appearing when i navigate to the page..Interestingly when i tried updating the date from firebug console(being on that page) it updated the field as well as datebox control.
I have no idea why this is happening..Need help, please respond JT
So finally i fixed the issue, by doing this
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'overrideDateFormat': '%m-%d-%Y',
'overrideHeaderFormat': '%m-%d-%Y'
});
setting the value of the input field explicitly
$(element).val('06-21-2012');
and then refreshing the datebox
$(element).trigger('datebox', {'method':'set', 'value':'06-21-2012'});
I found th solution, try this
$(element).trigger('datebox', { 'method': 'doset' });

jquery datepicker and custom validation

I need to add custom validation(I think) for validating input from an user. Here's my use case:
I'm using the jquery ui datepicker for selecting dates, with localization like this:
$.datepicker.setDefaults( $.datepicker.regional[ currentLocale ] );
I use the bassistance validation plugin, and using rules for date:true and such does not work with different formats(or if they do please tell me how!). So I've made my own date validation methods like this
$.validator.addMethod("validDate", function(value) {
return parseDateString(value) != null;
}, jQuery.validator.messages.date);
This all works very well except for the fact when selecting a date in the datepicker the validation is fired before the value of the componet is changed! So I actually validate the previous value....
Does anyone have a solution for me?
Thanks in advance:)
You could trigger validation upon the user closing the datepicker popup:
$("#birthdate").datepicker({
onClose: function() {
/* Validate a specific element: */
$("form").validate().element("#birthdate");
}
});
Using validate's element() function will enable you to validate a particular field immediately.
I've created an example here in which any date who's year != 2011 will trigger failed validation.

jQuery datepicker set selected date, on the fly

How can I change the selected date of jquery Date picker dynamically on the fly?
I have say created a inline date picker.
Then after some time, I want to reflect a different date there without recreating the datepicker from the scratch.
I tried the setDate method, but did not work, and there is not much documentation in the doc.
There is another (extended?) plugin here, but I want to use the plugin which is shipped with jquery.ui.all.js.
What version of jQuery-UI are you using? I've tested the following with 1.6r6, 1.7 and 1.7.1 and it works:
//Set DatePicker to October 3, 2008
$('#dateselector').datepicker("setDate", new Date(2008,9,03) );
Check that the date you are trying to set it to lies within the allowed date range if the minDate or maxDate options are set.
This example shows of how to use default value in the dropdown calendar and value in the text box. It also shows how to set default value to previous date.
selectedDate is another variable that holds current selected date of the calendar control
var date = new Date();
date.setDate(date.getDate() - 1);
$("#datepicker").datepicker({
dateFormat: "yy-mm-dd",
defaultDate: date,
onSelect: function () {
selectedDate = $.datepicker.formatDate("yy-mm-dd", $(this).datepicker('getDate'));
}
});
$("#datepicker").datepicker("setDate", date);
Noted that for DatePicker by Keith Wood (http://keith-wood.name/datepickRef.html) the following works - note that the setting of the default date is last:
$('#datepicker').datepick({
minDate: 0,
maxDate: '+145D',
multiSelect: 7,
renderer: $.datepick.themeRollerRenderer,
***defaultDate: new Date('1 January 2008')***
});
$('.date-pick').datePicker().val(new Date()).trigger('change')
finally, that what i look for the last few hours! I need initiate changes, not just setup date in text field!
For some reason, in some cases I couldn't make the setDate work.
A workaround I found is to simply update the value attribute of the given input.
Of course the datepicker itself won't be updated but if what you just look for is to display the date, it works fine.
var date = new Date(2008,9,3);
$("#your-input").val(date.getMonth()+"/"+date.getDate()+"/"+date.getFullYear());
// Will display 9/3/2008 in your #your-input input
This is a old thread but I just want to give some information how I have used. If you want to set today date you can simply apply it like below.
$("#datepickerid").datepicker("setDate", "0");
If you want to set some days before/after the current date then use the symbol -/+ symbol of how many days you want like below.
$("#datepickerid").datepicker("setDate", "-7");
$("#datepickerid").datepicker("setDate", "+5");
This works for me:
$("#dateselector").datepicker("option", "defaultDate", new Date(2008,9,3));
please Find below one it helps me a lot to set data function
$('#datepicker').datepicker({dateFormat: 'yy-mm-dd'}).datepicker('setDate', '2010-07-25');
setDate only seems to be an issue with an inline datepicker used in jquery UI, the specific error is InternalError: too much recursion.
In Html you can add your input field with a date picker like this
<input class="form-control date-picker fromDates" id="myDate" type="text">
and then in java script, initialize your datepicker and set your value to the date like this,
$('.fromDates').datepicker({
maxDate: '0',
dateFormat: "dd/mm/yy",
changeYear: true,
changeMonth: true,
yearRange: "-100:+0"
});
var myDateVal = moment('${value}').format('DD/MM/YYYY');
$('#myDate').datepicker().datepicker('setDate', myDateVal );
(In here fromdate attribute shows the previous dates of the current date)
var dt = new Date();
var renewal = moment(dt).add(1,'year').format('YYYY-MM-DD');
// moment().add(number, period)
// moment().subtract(number, period)
// period : year, days, hours, months, week...
I had a lot of trouble with the setDate method as well. seems to only work in v1. What does seem to work however is using the dpSetSelected method:
$("#dateselector").dpSetSelected(new Date(2010, 0, 26).asString());
good luck!
or you can simply have
$('.date-pick').datePicker().val(new Date()).trigger('change')

Resources