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;
};