08-18-2018 06:33 AM
I have created customized content model where 2 date control are there.
1)FromDate 2)ToDate
Now I want populate ToDate whenever FromDate change(base on some logic) and another is validation where ToDate should not be greater than FromDate(I have achieved this thing using validation-handler but the problem is it calling on every field of that form on keyup event).
Have any one implemented this type of thing?
share-config-custom.xml :
<field id="mbs:dosRangeTo" set="chargeBatchDocument" mandatory="true">
<control template="/org/alfresco/components/form/controls/dos_to_date.ftl"/>
<constraint-handlers>
<constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.validateMyDate" event="keyup" message="From Date Should not be greater than To Date"/>
</constraint-handlers>
</field>
JS File:
Alfresco.forms.validation.validateMyDate = function validateMyDate(field, args,event, form, silent, message)
{
var isCorrect = true;
var fromDate = field.form.prop_mbs_dosRangeFrom.value;
var toDate = field.form.prop_mbs_dosRangeTo.value;
if ((Date.parse(toDate) > Date.parse(fromDate))) {
YAHOO.util.Dom.setStyle(field.id+"-cntrl-date", "border", "2px solid red");
isCorrect = false;
} else {
YAHOO.util.Dom.setStyle(field.id+"-cntrl-date", "border", "");
isCorrect = true;
}
return isCorrect;
};
08-20-2018 01:25 AM
As dos_to_date.ftl component is not oob alfresco component, so you need to add content of it.
You can use daterange control of alfresco.If required you can customize it as well.It is saving from date and to date separated by pipe("|"), so you will be able to validate it inside the, validation handler.
08-20-2018 01:38 AM
I have create validation handler and it work but it calling on keyup event of every field of form not for that particular field.
08-20-2018 02:12 AM
Validation handler is component of form and not the component of any particular field.So whenever any field will gget changed it will try to validate all fields(by calling all validation handler).Validation handler will get called at the time of form submission as well.
If you would like to do something apart from validation you can do it inside, date-range.js file.Use Extension mechanism for extending it.
03-07-2019 04:04 AM
Hello,
I'm trying to do the pretty much the same thing as Sanjay, input Start date and End date and validate the end date is greater than start date. I'm trying to use the daterange.ftl control, it shows normally in my form however the icon form datepicker is kind of disabled, it doesn't open the datepicker to select a date and therefore it's impossible to fill in the date. For some reason, whenever i put the daterange.ftl,all datepickers would stop working within the form.
Any idea what could be the issue?
In my aspect, here's the property
<property name="lrwf:daterange">
<title>Date Range</title>
<type>d:date</type>
</property>
In share-config-custom.xml:
<field id="lrwf:daterange">
<control template="/org/alfresco/components/form/controls/daterange.ftl" />
</field>
Thank you!
Explore our Alfresco products with the links below. Use labels to filter content by product module.