07-12-2012 08:21 PM
…
<@script type="text/javascript" src="${page.url.context}/res/js/formValidation.js"></@script>
…
in the same jar file at source/web/js/formValidation.js:/**
* Corporate Document Expiry and Reminder date's validation handler, tests that the expiry date > reminder date.
*
* @method corporateDatesValidation
* @param field {object} The element representing the field the validation is for
* @param args {object} Not used
* @param event {object} The event that caused this handler to be called, maybe null
* @param form {object} The forms runtime class instance the field is being managed by
* @param silent {boolean} Determines whether the user should be informed upon failure
* @param message {string} Message to display when validation fails, maybe null
* @static
*/
Alfresco.forms.validation.corporateDates = function corporateDatesValidation(field, args, event, form, silent, message)
{
Alfresco.logger.warn("Validating state of field '" + field.id + "'");
var valid = true;
valid = YAHOO.lang.trim(field.value).length !== 0;
if (valid)
{
Alfresco.logger.warn("field value length test passed, checking dates can be parsed");
// check dates can be parsed
str_expiryDate = field.form.prop_mcwf_expiryDate.value;
str_reminderDate = field.form.prop_mcwf_reminderDate.value;
Alfresco.logger.warn("Expiry Date: " + str_expiryDate + " | Reminder Date: " + str_reminderDate);
d_expiryDate = Date.parse(str_expiryDate);
d_reminderDate = Date.parse(str_reminderDate);
if (d_expiryDate && d_reminderDate)
{
Alfresco.logger.warn("Dates Parsed, checking expiry > reminder");
// check expirydate>reminder date
valid = d_expiryDate>d_reminderDate;
Alfresco.logger.warn("The result of the date validation was: " + valid);
}
}
if (!valid && !silent && form)
{
// if the keyCode from the event is the TAB or SHIFT keys don't show the error
if (event && event.keyCode != 9 && event.keyCode != 16 || !event)
{
form.addError("Expiry and Review dates are mandatory. Expiry date must be after Review date.", field);
}
}
return valid;
};
and in my share-config-custom.xml I have: <config evaluator="task-type" condition="mcwf:setExpirationTask">
<forms>
<form>
<field-visibility>
<show id="mcwf:expiryDate" />
<show id="mcwf:reminderDate" />
<show id="transitions" />
</field-visibility>
<appearance>
<set id="" appearance="title" label-id="workflow.set.general" />
<set id="other" appearance="title" label-id="workflow.set.other" />
<set id="response" appearance="title" labelid="workflow.set.response" />
<field id="mcwf:expiryDate" set="other">
<constraint-handler>
<constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.corporateDates" event="keyup" />
</constraint-handler>
</field>
<field id="mcwf:reminderDate" set="other">
<constraint-handler>
<constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.corporateDates" event="keyup" />
</constraint-handler>
</field>
<field id="transitions" set="response" />
</appearance>
</form>
<form id="workflow-details">
<field-visibility>
</field-visibility>
<appearance>
</appearance>
</form>
</forms>
</config>
09:52:34 DEBUG - Determining whether submit elements can be enabled…
09:52:34 DEBUG - Validating mandatory state of field 'page_x002e_data-form_x002e_task-edit_x0023_default_prop_mcwf_expiryDate'
09:52:34 DEBUG - Validating mandatory state of field 'page_x002e_data-form_x002e_task-edit_x0023_default_prop_mcwf_reminderDate'
09:52:34 DEBUG - Validating field 'page_x002e_data-form_x002e_task-edit_x0023_default_prop_mcwf_expiryDate-cntrl-date' has a valid date and time
09:52:34 DEBUG - Validating field 'page_x002e_data-form_x002e_task-edit_x0023_default_prop_mcwf_reminderDate-cntrl-date' has a valid date and time
YAHOO.Bubbling.fire("registerValidationHandler",{fieldId: "page_x002e_data-form_x002e_task-edit_x0023_default_prop_mcwf_expiryDate",handler: Alfresco.forms.validation.corporateDates,when: "onchange"});
.07-16-2012 01:29 AM
YAHOO.Bubbling.fire("registerValidationHandler",{fieldId: "[FIELD_ID]",handler: [VALIDATION_HANDLER],when: "onchange"});
where [FIELD_ID] is the html id of the field, and [VALIDATION_HANDLER] is the name of your custom validation handler (something like Alfresco.forms.validation.dateValidator). The event is up to you, but as it is a hidden field keyboard and focus based events may not work. onchange seems the best fit for date fields.<#if field.control.params.showTime?? && field.control.params.showTime == "true"><#assign showTime=true><#else><#assign showTime=false></#if>
<#if showTime><#assign viewFormat>${msg("form.control.date-picker.view.time.format")}</#assign><#else><#assign viewFormat>${msg("form.control.date-picker.view.date.format")}</#assign></#if>
<#assign disabled=field.disabled>
<#if field.control.params.forceEditable?? && field.control.params.forceEditable == "true">
<#assign disabled=false>
</#if>
<#assign multiValued=false>
<#if field.value != "" && field.value?index_of(",") != -1>
<#assign multiValued=true>
</#if>
<#if form.capabilities?? && form.capabilities.javascript?? && form.capabilities.javascript == false><#assign jsDisabled=true><#else><#assign jsDisabled=false></#if>
<div class="form-field">
<#if form.mode == "view">
<div class="viewmode-field">
<#if field.mandatory && field.value == "">
<span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
</#if>
<span class="viewmode-label">${field.label?html}:</span>
<span class="viewmode-value">
<#if field.value == "">
${msg("form.control.novalue")}
<#elseif !multiValued>
${xmldate(field.value)?string(viewFormat)}
<#else>
<#list field.value?split(",") as dateEl>
${xmldate(dateEl)?string(viewFormat)}<#if dateEl_has_next>,</#if>
</#list>
</#if>
</span>
</div>
<#elseif !multiValued>
<#if jsDisabled>
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<input id="${fieldHtmlId}" name="${field.name}" type="text" class="date-entry" value="${field.value?html}" <#if field.description??>title="${field.description}"</#if> <#if disabled>disabled="true"<#else>tabindex="0"</#if> />
<div class="format-info">
<span class="date-format">${msg("form.control.date-picker.entry.datetime.format.nojs")}</span>
</div>
<#else>
<#assign controlId = fieldHtmlId + "-cntrl">
<script type="text/javascript">//<![CDATA[
(function()
{
new Alfresco.DatePicker("${controlId}", "${fieldHtmlId}").setOptions(
{
<#if form.mode == "view" || disabled>disabled: true,</#if>
currentValue: "${field.value?js_string}",
showTime: ${showTime?string},
mandatory: ${field.mandatory?string}
}).setMessages(
${messages}
);
})();
//]]></script>
<input id="${fieldHtmlId}" type="hidden" name="${field.name}" value="${field.value?html}" />
<label for="${controlId}-date">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<input id="${controlId}-date" name="-" type="text" class="date-entry" <#if field.description??>title="${field.description}"</#if> <#if disabled>disabled="true"<#else>tabindex="0"</#if> />
<#if disabled == false>
<a id="${controlId}-icon"><img src="${url.context}/res/components/form/images/calendar.png" class="datepicker-icon" tabindex="0"/></a>
</#if>
<div id="${controlId}" class="datepicker"></div>
<#if showTime>
<input id="${controlId}-time" name="-" type="text" class="time-entry" <#if field.description??>title="${field.description}"</#if> <#if disabled>disabled="true"<#else>tabindex="0"</#if> />
</#if>
<@formLib.renderFieldHelp field=field />
<div class="format-info">
<span class="date-format">${msg("form.control.date-picker.display.date.format")}</span>
<#if showTime><span class="time-format<#if disabled>-disabled</#if>">${msg("form.control.date-picker.display.time.format")}</span></#if>
</div>
<script type="text/javascript">//<![CDATA[
setTimeout(function(){YAHOO.Bubbling.fire("registerValidationHandler",{fieldId: "${fieldHtmlId}",handler: Alfresco.forms.validation.corporateDates,when: "onchange"});},2000);
//]]></script>
</#if>
</#if>
</div>
08-01-2012 06:54 AM
05-28-2013 12:38 PM
08-27-2015 06:20 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.