Merge pull request #336 from kurund/memcache-fixes
[civicrm-core.git] / templates / CRM / Form / validate.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 {literal}
31 <script type="text/javascript" >
32 cj(function($) {
33 var params = {
34 'errorClass': 'crm-inline-error',
35 messages: {{/literal}
36 required: "{ts escape='js'}This field is required.{/ts}",
37 remote: "{ts escape='js'}Please fix this field.{/ts}",
38 email: "{ts escape='js'}Please enter a valid email address.{/ts}",
39 url: "{ts escape='js'}Please enter a valid URL.{/ts}",
40 date: "{ts escape='js'}Please enter a valid date.{/ts}",
41 dateISO: "{ts escape='js'}Please enter a valid date (ISO).{/ts}",
42 number: "{ts escape='js'}Please enter a valid number.{/ts}",
43 digits: "{ts escape='js'}Please enter only digits.{/ts}",
44 creditcard: "{ts escape='js'}Please enter a valid credit card number.{/ts}",
45 equalTo: "{ts escape='js'}Please enter the same value again.{/ts}",
46 accept: "{ts escape='js'}Please enter a value with a valid extension.{/ts}",
47 maxlength: $.validator.format("{ts escape='js'}Please enter no more than {ldelim}0{rdelim} characters.{/ts}"),
48 minlength: $.validator.format("{ts escape='js'}Please enter at least {ldelim}0{rdelim} characters.{/ts}"),
49 rangelength: $.validator.format("{ts escape='js'}Please enter a value between {ldelim}0{rdelim} and {ldelim}1{rdelim} characters long.{/ts}"),
50 range: $.validator.format("{ts escape='js'}Please enter a value between {ldelim}0{rdelim} and {ldelim}1{rdelim}.{/ts}"),
51 max: $.validator.format("{ts escape='js'}Please enter a value less than or equal to {ldelim}0{rdelim}.{/ts}"),
52 min: $.validator.format("{ts escape='js'}Please enter a value greater than or equal to {ldelim}0{rdelim}.{/ts}")
53 {literal}}
54 };
55
56 // use civicrm notifications when there are errors
57 params.invalidHandler = function(form, validator) {
58 var errors = validator.errorList;
59 if (CRM && CRM.config && CRM.config.urlIsPublic === false) {
60 for (var i in errors) {
61 $(errors[i].element).crmError(errors[i].message);
62 }
63 }
64 else {
65 alert({/literal}"{ts escape='js'}Please review and correct the highlighted fields before continuing.{/ts}"{literal});
66 }
67 };
68
69 CRM.validate.params = CRM.validate.params || {};
70 $.extend(CRM.validate.params, params);
71
72 {/literal}
73 {if $form && $form.formName}
74 $("#{$form.formName}").validate(params);
75 {literal}
76 // Call any post-initialization callbacks
77 if (CRM.validate && CRM.validate.functions) {
78 for (var i in CRM.validate.functions) {
79 CRM.validate.functions[i]();
80 }
81 }
82 {/literal}
83 {/if}
84 });
85 </script>