| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.5 | |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 6 | +--------------------------------------------------------------------+ |
| 7 | | This file is a part of CiviCRM. | |
| 8 | | | |
| 9 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 10 | | under the terms of the GNU Affero General Public License | |
| 11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 12 | | | |
| 13 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 16 | | See the GNU Affero General Public License for more details. | |
| 17 | | | |
| 18 | | You should have received a copy of the GNU Affero General Public | |
| 19 | | License and the CiviCRM Licensing Exception along | |
| 20 | | with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | *} |
| 26 | |
| 27 | {* Initialize jQuery validate *} |
| 28 | {* Extra params and functions may be added to the CRM.validate object before this template is loaded *} |
| 29 | |
| 30 | {if !$crm_form_validate_included} |
| 31 | {assign var=crm_form_validate_included value=1} |
| 32 | |
| 33 | {literal} |
| 34 | <script type="text/javascript" > |
| 35 | cj(function($) { |
| 36 | var messages = {{/literal} |
| 37 | required: "{ts escape='js'}This field is required.{/ts}", |
| 38 | remote: "{ts escape='js'}Please fix this field.{/ts}", |
| 39 | email: "{ts escape='js'}Please enter a valid email address.{/ts}", |
| 40 | url: "{ts escape='js'}Please enter a valid URL.{/ts}", |
| 41 | date: "{ts escape='js'}Please enter a valid date.{/ts}", |
| 42 | dateISO: "{ts escape='js'}Please enter a valid date (YYYY-MM-DD).{/ts}", |
| 43 | number: "{ts escape='js'}Please enter a valid number.{/ts}", |
| 44 | digits: "{ts escape='js'}Please enter only digits.{/ts}", |
| 45 | creditcard: "{ts escape='js'}Please enter a valid credit card number.{/ts}", |
| 46 | equalTo: "{ts escape='js'}Please enter the same value again.{/ts}", |
| 47 | accept: "{ts escape='js'}Please enter a value with a valid extension.{/ts}", |
| 48 | maxlength: $.validator.format("{ts escape='js'}Please enter no more than {ldelim}0{rdelim} characters.{/ts}"), |
| 49 | minlength: $.validator.format("{ts escape='js'}Please enter at least {ldelim}0{rdelim} characters.{/ts}"), |
| 50 | rangelength: $.validator.format("{ts escape='js'}Please enter a value between {ldelim}0{rdelim} and {ldelim}1{rdelim} characters long.{/ts}"), |
| 51 | range: $.validator.format("{ts escape='js'}Please enter a value between {ldelim}0{rdelim} and {ldelim}1{rdelim}.{/ts}"), |
| 52 | max: $.validator.format("{ts escape='js'}Please enter a value less than or equal to {ldelim}0{rdelim}.{/ts}"), |
| 53 | min: $.validator.format("{ts escape='js'}Please enter a value greater than or equal to {ldelim}0{rdelim}.{/ts}") |
| 54 | {literal}}; |
| 55 | |
| 56 | var params = { |
| 57 | 'errorClass': 'crm-inline-error', |
| 58 | messages: {} |
| 59 | }; |
| 60 | |
| 61 | // use civicrm notifications when there are errors |
| 62 | params.invalidHandler = function(form, validator) { |
| 63 | var errors = validator.errorList; |
| 64 | {/literal}{if !$urlIsPublic}{literal} |
| 65 | for (var i in errors) { |
| 66 | $(errors[i].element).crmError(errors[i].message); |
| 67 | } |
| 68 | {/literal}{else} |
| 69 | alert("{ts escape='js'}Please review and correct the highlighted fields before continuing.{/ts}"); |
| 70 | {/if}{literal} |
| 71 | }; |
| 72 | |
| 73 | CRM.validate.params = CRM.validate.params || {}; |
| 74 | $.extend(CRM.validate.params, params); |
| 75 | $.extend($.validator.messages, messages); |
| 76 | |
| 77 | {/literal} |
| 78 | {if $form && $form.formName} |
| 79 | $("#{$form.formName}").validate(params); |
| 80 | {literal} |
| 81 | // Call any post-initialization callbacks |
| 82 | if (CRM.validate && CRM.validate.functions.length) { |
| 83 | $.each(CRM.validate.functions, function(i, func) { |
| 84 | func(); |
| 85 | }); |
| 86 | } |
| 87 | {/literal} |
| 88 | {/if} |
| 89 | }); |
| 90 | </script> |
| 91 | {/if} |