Reputation: 131
I want to get the date from a rich:calendar component in javascript in order to compare it with another date and disable the dates which are over or under each other ("from" date can't be after "to" date) I know how to disable dates, but I haven't been able to get the date, I've tried with:
#{rich:element('FromDate')}.component.getSelectedDate().getTime()
#{rich:component('FromDate')}.getSelectedDate().getTime()
#{rich:component('FromDate')}.Date.getTime()
#{rich:component('FromDate')}.getTime()
the idea is to after it make a comparation like
function disablementFunction(day){
if (#{rich:element('FromDate')}.component.getSelectedDate().getTime() -
day.date.getTime() >= 0) {
return false;
}
return true;
}
Upvotes: 0
Views: 6160
Reputation: 6667
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<rich:calendar id="clndUATOnDateId" datePattern="dd-MMM-yyyy"></rich:calendar>
<h:commandButton title="Submit" value="Submit" onclick="addUATDates();"></h:commandButton>
<script type="text/javascript">
function addUATDates() {
var uatOn = document.getElementById("addUATDateForm:clndUATOnDateIdInputDate");
alert(uatOn.value);
}
</script>
Write 'InputDate' after clndUATOnDateId in script to get date. The output of selected rich calendar date (Ex: 15-Sep-2012) is dispalyed in alert popup.
Upvotes: 0
Reputation: 1954
You can use Richfaces js api to get the current date:
RichFaces.$('FromDate').currentDate.getTime()
Just for clarification your code snippet will become something like:
function disablementFunction(day){
if (RichFaces.$('FromDate').currentDate.getTime() >= 0) {
return false;
}
return true;
}
Of Course you can still refer to this date using el expression:
#{rich:component('FromDate')}.currentDate.getTime();
Upvotes: 3