jQuery-Validation-Engine-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTI1NjRmMjI1MTU2NDlmZjk5NjdkMGM3OTkyN2I3ZGMzYmY4Njc5NA==
5
+ data.tar.gz: !binary |-
6
+ NTg1NWFmNDNiZDRhYzFlNTU0OGZlZTJkYTEzOWNhMzEyNGNlZGRmZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MzRlN2NkYzIxMmQzNDIzNTMzYTczYzQwOGFiZWMyYjc2Yzg1ZjI1MDU5OGRm
10
+ YmUzMGRkZDY0ZWU0NjliNjZmNmY2ZTljYzg3ZWJiMGUxZDgyMzc4OTY4MGYy
11
+ YWU3M2ZlMTNlYTU5M2JkNzhhMTcwODQ0YmZkNjdhN2M3MzgzMTA=
12
+ data.tar.gz: !binary |-
13
+ M2JiNWNlNmJiN2RkYWNlOTI5YzY0ZTlhODkyY2Q1N2JhM2I1ZjU4MTE0Njdh
14
+ NjNiOTA2ZjQ2YzI2MTE4YWNkOTIwOGUyNDMxYmU1MTFjMjczZjI3YTQ4ZDBm
15
+ N2E0MmNlNGFmMzc1MDY5MDEzZTRlMDcwZjY5N2VmMWQ3YzhjYjA=
@@ -2,7 +2,7 @@ module JQuery
2
2
  module Validation
3
3
  module Engine
4
4
  module Rails
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
  end
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Inline Form Validation Engine 2.6.1, jQuery plugin
2
+ * Inline Form Validation Engine 2.6.2, jQuery plugin
3
3
  *
4
4
  * Copyright(c) 2010, Cedric Dugas
5
5
  * http://www.position-absolute.com
@@ -12,28 +12,28 @@
12
12
  */
13
13
  (function($) {
14
14
 
15
- "use strict";
15
+ "use strict";
16
16
 
17
- var methods = {
17
+ var methods = {
18
18
 
19
- /**
20
- * Kind of the constructor, called before any action
21
- * @param {Map} user options
22
- */
23
- init: function(options) {
24
- var form = this;
25
- if (!form.data('jqv') || form.data('jqv') == null ) {
26
- options = methods._saveOptions(form, options);
27
- // bind all formError elements to close on click
28
- $(".formError").live("click", function() {
29
- $(this).fadeOut(150, function() {
30
- // remove prompt once invisible
31
- $(this).parent('.formErrorOuter').remove();
32
- $(this).remove();
33
- });
34
- });
35
- }
36
- return this;
19
+ /**
20
+ * Kind of the constructor, called before any action
21
+ * @param {Map} user options
22
+ */
23
+ init: function(options) {
24
+ var form = this;
25
+ if (!form.data('jqv') || form.data('jqv') == null ) {
26
+ options = methods._saveOptions(form, options);
27
+ // bind all formError elements to close on click
28
+ $(document).on("click", ".formError", function() {
29
+ $(this).fadeOut(150, function() {
30
+ // remove prompt once invisible
31
+ $(this).parent('.formErrorOuter').remove();
32
+ $(this).remove();
33
+ });
34
+ });
35
+ }
36
+ return this;
37
37
  },
38
38
  /**
39
39
  * Attachs jQuery.validationEngine to form.submit and field.blur events
@@ -42,11 +42,6 @@
42
42
  */
43
43
  attach: function(userOptions) {
44
44
 
45
- if(!$(this).is("form")) {
46
- alert("Sorry, jqv.attach() only applies to a form");
47
- return this;
48
- }
49
-
50
45
  var form = this;
51
46
  var options;
52
47
 
@@ -58,10 +53,10 @@
58
53
  options.validateAttribute = (form.find("[data-validation-engine*=validate]").length) ? "data-validation-engine" : "class";
59
54
  if (options.binded) {
60
55
 
61
- // bind fields
62
- form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").not("[type=radio]").not(".datepicker").bind(options.validationEventTrigger, methods._onFieldEvent);
63
- form.find("["+options.validateAttribute+"*=validate][type=checkbox],["+options.validateAttribute+"*=validate][type=radio]").bind("click", methods._onFieldEvent);
64
- form.find("["+options.validateAttribute+"*=validate][class*=datepicker]").bind(options.validationEventTrigger,{"delay": 300}, methods._onFieldEvent);
56
+ // delegate fields
57
+ form.on(options.validationEventTrigger, "["+options.validateAttribute+"*=validate]:not([type=checkbox]):not([type=radio]):not(.datepicker)", methods._onFieldEvent);
58
+ form.on("click", "["+options.validateAttribute+"*=validate][type=checkbox],["+options.validateAttribute+"*=validate][type=radio]", methods._onFieldEvent);
59
+ form.on(options.validationEventTrigger,"["+options.validateAttribute+"*=validate][class*=datepicker]", {"delay": 300}, methods._onFieldEvent);
65
60
  }
66
61
  if (options.autoPositionUpdate) {
67
62
  $(window).bind("resize", {
@@ -69,40 +64,34 @@
69
64
  "formElem": form
70
65
  }, methods.updatePromptsPosition);
71
66
  }
67
+ form.on("click","a[data-validation-engine-skip], a[class*='validate-skip'], button[data-validation-engine-skip], button[class*='validate-skip'], input[data-validation-engine-skip], input[class*='validate-skip']", methods._submitButtonClick);
68
+ form.removeData('jqv_submitButton');
69
+
72
70
  // bind form.submit
73
- form.bind("submit", methods._onSubmitEvent);
71
+ form.on("submit", methods._onSubmitEvent);
74
72
  return this;
75
73
  },
76
74
  /**
77
75
  * Unregisters any bindings that may point to jQuery.validaitonEngine
78
76
  */
79
77
  detach: function() {
80
-
81
- if(!$(this).is("form")) {
82
- alert("Sorry, jqv.detach() only applies to a form");
83
- return this;
84
- }
85
78
 
86
79
  var form = this;
87
80
  var options = form.data('jqv');
88
81
 
89
82
  // unbind fields
90
- form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").unbind(options.validationEventTrigger, methods._onFieldEvent);
91
- form.find("["+options.validateAttribute+"*=validate][type=checkbox],[class*=validate][type=radio]").unbind("click", methods._onFieldEvent);
83
+ form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").off(options.validationEventTrigger, methods._onFieldEvent);
84
+ form.find("["+options.validateAttribute+"*=validate][type=checkbox],[class*=validate][type=radio]").off("click", methods._onFieldEvent);
92
85
 
93
86
  // unbind form.submit
94
- form.unbind("submit", methods.onAjaxFormComplete);
95
-
96
- // unbind live fields (kill)
97
- form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").die(options.validationEventTrigger, methods._onFieldEvent);
98
- form.find("["+options.validateAttribute+"*=validate][type=checkbox]").die("click", methods._onFieldEvent);
99
-
100
- // unbind form.submit
101
- form.die("submit", methods.onAjaxFormComplete);
87
+ form.off("submit", methods._onSubmitEvent);
102
88
  form.removeData('jqv');
89
+
90
+ form.off("click", "a[data-validation-engine-skip], a[class*='validate-skip'], button[data-validation-engine-skip], button[class*='validate-skip'], input[data-validation-engine-skip], input[class*='validate-skip']", methods._submitButtonClick);
91
+ form.removeData('jqv_submitButton');
103
92
 
104
93
  if (options.autoPositionUpdate)
105
- $(window).unbind("resize", methods.updatePromptsPosition);
94
+ $(window).off("resize", methods.updatePromptsPosition);
106
95
 
107
96
  return this;
108
97
  },
@@ -115,27 +104,34 @@
115
104
  validate: function() {
116
105
  var element = $(this);
117
106
  var valid = null;
118
- if(element.is("form") && !element.hasClass('validating')) {
119
- element.addClass('validating');
120
- var options = element.data('jqv');
121
- valid = methods._validateFields(this);
122
-
123
- // If the form doesn't validate, clear the 'validating' class before the user has a chance to submit again
124
- setTimeout(function(){
125
- element.removeClass('validating');
126
- }, 100);
127
- if (valid && options.onSuccess) {
128
- options.onSuccess();
129
- } else if (!valid && options.onFailure) {
130
- options.onFailure();
107
+
108
+ if (element.is("form") || element.hasClass("validationEngineContainer")) {
109
+ if (element.hasClass('validating')) {
110
+ // form is already validating.
111
+ // Should abort old validation and start new one. I don't know how to implement it.
112
+ return false;
113
+ } else {
114
+ element.addClass('validating');
115
+ var options = element.data('jqv');
116
+ var valid = methods._validateFields(this);
117
+
118
+ // If the form doesn't validate, clear the 'validating' class before the user has a chance to submit again
119
+ setTimeout(function(){
120
+ element.removeClass('validating');
121
+ }, 100);
122
+ if (valid && options.onSuccess) {
123
+ options.onSuccess();
124
+ } else if (!valid && options.onFailure) {
125
+ options.onFailure();
126
+ }
131
127
  }
132
- } else if (element.is('form')) {
128
+ } else if (element.is('form') || element.hasClass('validationEngineContainer')) {
133
129
  element.removeClass('validating');
134
130
  } else {
135
131
  // field validation
136
- var form = element.closest('form');
137
- var options = (form.data('jqv')) ? form.data('jqv') : $.validationEngine.defaults;
138
- valid = methods._validateField(element, options);
132
+ var form = element.closest('form, .validationEngineContainer'),
133
+ options = (form.data('jqv')) ? form.data('jqv') : $.validationEngine.defaults,
134
+ valid = methods._validateField(element, options);
139
135
 
140
136
  if (valid && options.onFieldSuccess)
141
137
  options.onFieldSuccess();
@@ -143,6 +139,10 @@
143
139
  options.onFieldFailure();
144
140
  }
145
141
  }
142
+ if(options.onValidationComplete) {
143
+ // !! ensures that an undefined return is interpreted as return false but allows a onValidationComplete() to possibly return true and have form continue processing
144
+ return !!options.onValidationComplete(form, valid);
145
+ }
146
146
  return valid;
147
147
  },
148
148
  /**
@@ -155,7 +155,7 @@
155
155
  var noAnimation = event.data.noAnimation;
156
156
  }
157
157
  else
158
- var form = $(this.closest('form'));
158
+ var form = $(this.closest('form, .validationEngineContainer'));
159
159
 
160
160
  var options = form.data('jqv');
161
161
  // No option, take default one
@@ -180,8 +180,7 @@
180
180
  * @param {String} possible values topLeft, topRight, bottomLeft, centerRight, bottomRight
181
181
  */
182
182
  showPrompt: function(promptText, type, promptPosition, showArrow) {
183
-
184
- var form = this.closest('form');
183
+ var form = this.closest('form, .validationEngineContainer');
185
184
  var options = form.data('jqv');
186
185
  // No option, take default one
187
186
  if(!options)
@@ -197,12 +196,12 @@
197
196
  * Closes form error prompts, CAN be invidual
198
197
  */
199
198
  hide: function() {
200
- var form = $(this).closest('form');
199
+ var form = $(this).closest('form, .validationEngineContainer');
201
200
  var options = form.data('jqv');
202
201
  var fadeDuration = (options && options.fadeDuration) ? options.fadeDuration : 0.3;
203
202
  var closingtag;
204
203
 
205
- if($(this).is("form")) {
204
+ if($(this).is("form") || $(this).hasClass("validationEngineContainer")) {
206
205
  closingtag = "parentForm"+methods._getClassName($(this).attr("id"));
207
206
  } else {
208
207
  closingtag = methods._getClassName($(this).attr("id")) +"formError";
@@ -220,8 +219,8 @@
220
219
 
221
220
  var form = this;
222
221
  var options = form.data('jqv');
223
- var duration = options ? options.fadeDuration:0.3;
224
- $('.formError').fadeTo(duration, 0.3, function() {
222
+ var duration = options ? options.fadeDuration:300;
223
+ $('.formError').fadeTo(duration, 300, function() {
225
224
  $(this).parent('.formErrorOuter').remove();
226
225
  $(this).remove();
227
226
  });
@@ -233,7 +232,7 @@
233
232
  */
234
233
  _onFieldEvent: function(event) {
235
234
  var field = $(this);
236
- var form = field.closest('form');
235
+ var form = field.closest('form, .validationEngineContainer');
237
236
  var options = form.data('jqv');
238
237
  options.eventTrigger = "field";
239
238
  // validate the current field
@@ -257,6 +256,18 @@
257
256
  _onSubmitEvent: function() {
258
257
  var form = $(this);
259
258
  var options = form.data('jqv');
259
+
260
+ //check if it is trigger from skipped button
261
+ if (form.data("jqv_submitButton")){
262
+ var submitButton = $("#" + form.data("jqv_submitButton"));
263
+ if (submitButton){
264
+ if (submitButton.length > 0){
265
+ if (submitButton.hasClass("validate-skip") || submitButton.attr("data-validation-engine-skip") == "true")
266
+ return true;
267
+ }
268
+ }
269
+ }
270
+
260
271
  options.eventTrigger = "submit";
261
272
 
262
273
  // validate each field
@@ -328,9 +339,18 @@
328
339
  errorFound |= methods._validateField(field, options);
329
340
  if (errorFound && first_err==null)
330
341
  if (field.is(":hidden") && options.prettySelect)
331
- first_err = field = form.find("#" + options.usePrefix + methods._jqSelector(field.attr('id')) + options.useSuffix);
332
- else
333
- first_err=field;
342
+ first_err = field = form.find("#" + options.usePrefix + methods._jqSelector(field.attr('id')) + options.useSuffix);
343
+ else {
344
+
345
+ //Check if we need to adjust what element to show the prompt on
346
+ //and and such scroll to instead
347
+ if(field.data('jqv-prompt-at') instanceof jQuery ){
348
+ field = field.data('jqv-prompt-at');
349
+ } else if(field.data('jqv-prompt-at')) {
350
+ field = $(field.data('jqv-prompt-at'));
351
+ }
352
+ first_err=field;
353
+ }
334
354
  if (options.doNotShowAllErrosOnSubmit)
335
355
  return false;
336
356
  names.push(field.attr('name'));
@@ -426,7 +446,11 @@
426
446
  return options.onBeforeAjaxFormValidation(form, options);
427
447
  },
428
448
  error: function(data, transport) {
429
- methods._ajaxError(data, transport);
449
+ if (options.onFailure) {
450
+ options.onFailure(data, transport);
451
+ } else {
452
+ methods._ajaxError(data, transport);
453
+ }
430
454
  },
431
455
  success: function(json) {
432
456
  if ((dataType == "json") && (json !== true)) {
@@ -497,7 +521,7 @@
497
521
  ++$.validationEngine.fieldIdCounter;
498
522
  }
499
523
 
500
- if (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden"))
524
+ if (!options.validateNonVisibleFields && (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden")))
501
525
  return false;
502
526
 
503
527
  var rulesParsing = field.attr(options.validateAttribute);
@@ -523,7 +547,7 @@
523
547
  limitErrors = true;
524
548
  }
525
549
 
526
- var form = $(field.closest("form"));
550
+ var form = $(field.closest("form, .validationEngineContainer"));
527
551
  // Fix for adding spaces in the rules
528
552
  for (var i = 0; i < rules.length; i++) {
529
553
  rules[i] = rules[i].replace(" ", "");
@@ -684,14 +708,22 @@
684
708
  }
685
709
  }
686
710
  // If the rules required is not added, an empty field is not validated
687
- if(!required && field.val() && field.val().length < 1) options.isError = false;
711
+ //the 3rd condition is added so that even empty password fields should be equal
712
+ //otherwise if one is filled and another left empty, the "equal" condition would fail
713
+ //which does not make any sense
714
+ if(!required && !(field.val()) && field.val().length < 1 && rules.indexOf("equals") < 0) options.isError = false;
688
715
 
689
716
  // Hack for radio/checkbox group button, the validation go into the
690
717
  // first radio/checkbox of the group
691
718
  var fieldType = field.prop("type");
719
+ var positionType=field.data("promptPosition") || options.promptPosition;
692
720
 
693
721
  if ((fieldType == "radio" || fieldType == "checkbox") && form.find("input[name='" + fieldName + "']").size() > 1) {
722
+ if(positionType === 'inline') {
723
+ field = $(form.find("input[name='" + fieldName + "'][type!=hidden]:last"));
724
+ } else {
694
725
  field = $(form.find("input[name='" + fieldName + "'][type!=hidden]:first"));
726
+ }
695
727
  options.showArrow = false;
696
728
  }
697
729
 
@@ -720,6 +752,13 @@
720
752
 
721
753
  methods._handleStatusCssClasses(field, options);
722
754
 
755
+ /* run callback function for each field */
756
+ if (options.isError && options.onFieldFailure)
757
+ options.onFieldFailure(field);
758
+
759
+ if (!options.isError && options.onFieldSuccess)
760
+ options.onFieldSuccess(field);
761
+
723
762
  return options.isError;
724
763
  },
725
764
  /**
@@ -764,12 +803,18 @@
764
803
  // If we are using the custon validation type, build the index for the rule.
765
804
  // Otherwise if we are doing a function call, make the call and return the object
766
805
  // that is passed back.
767
- var beforeChangeRule = rule;
768
- if (rule == "custom") {
769
- var custom_validation_type_index = jQuery.inArray(rule, rules)+ 1;
770
- var custom_validation_type = rules[custom_validation_type_index];
771
- rule = "custom[" + custom_validation_type + "]";
806
+ var rule_index = jQuery.inArray(rule, rules);
807
+ if (rule === "custom" || rule === "funcCall") {
808
+ var custom_validation_type = rules[rule_index + 1];
809
+ rule = rule + "[" + custom_validation_type + "]";
810
+ // Delete the rule from the rules array so that it doesn't try to call the
811
+ // same rule over again
812
+ delete(rules[rule_index]);
772
813
  }
814
+ // Change the rule to the composite rule, if it was different from the original
815
+ var alteredRule = rule;
816
+
817
+
773
818
  var element_classes = (field.attr("data-validation-engine")) ? field.attr("data-validation-engine") : field.attr("class");
774
819
  var element_classes_array = element_classes.split(" ");
775
820
 
@@ -784,7 +829,7 @@
784
829
  // If the original validation method returned an error and we have a custom error message,
785
830
  // return the custom message instead. Otherwise return the original error message.
786
831
  if (errorMsg != undefined) {
787
- var custom_message = methods._getCustomErrorMessage($(field), element_classes_array, beforeChangeRule, options);
832
+ var custom_message = methods._getCustomErrorMessage($(field), element_classes_array, alteredRule, options);
788
833
  if (custom_message) errorMsg = custom_message;
789
834
  }
790
835
  return errorMsg;
@@ -792,7 +837,7 @@
792
837
  },
793
838
  _getCustomErrorMessage:function (field, classes, rule, options) {
794
839
  var custom_message = false;
795
- var validityProp = methods._validityProp[rule];
840
+ var validityProp = /^custom\[.*\]$/.test(rule) ? methods._validityProp["custom"] : methods._validityProp[rule];
796
841
  // If there is a validityProp for this rule, check to see if the field has an attribute for it
797
842
  if (validityProp != undefined) {
798
843
  custom_message = field.attr("data-errormessage-"+validityProp);
@@ -867,9 +912,16 @@
867
912
  case "select-one":
868
913
  case "select-multiple":
869
914
  default:
870
-
871
- if (! $.trim(field.val()) || field.val() == field.attr("data-validation-placeholder") || field.val() == field.attr("placeholder"))
915
+ var field_val = $.trim( field.val() );
916
+ var dv_placeholder = $.trim( field.attr("data-validation-placeholder") );
917
+ var placeholder = $.trim( field.attr("placeholder") );
918
+ if (
919
+ ( !field_val )
920
+ || ( dv_placeholder && field_val == dv_placeholder )
921
+ || ( placeholder && field_val == placeholder )
922
+ ) {
872
923
  return options.allrules[rules[i]].alertText;
924
+ }
873
925
  break;
874
926
  case "radio":
875
927
  case "checkbox":
@@ -881,7 +933,7 @@
881
933
  break;
882
934
  }
883
935
  // old validation style
884
- var form = field.closest("form");
936
+ var form = field.closest("form, .validationEngineContainer");
885
937
  var name = field.attr("name");
886
938
  if (form.find("input[name='" + name + "']:checked").size() == 0) {
887
939
  if (form.find("input[name='" + name + "']:visible").size() == 1)
@@ -906,7 +958,7 @@
906
958
  var classGroup = "["+options.validateAttribute+"*=" +rules[i + 1] +"]";
907
959
  var isValid = false;
908
960
  // Check all fields from the group
909
- field.closest("form").find(classGroup).each(function(){
961
+ field.closest("form, .validationEngineContainer").find(classGroup).each(function(){
910
962
  if(!methods._required($(this), rules, i, options)){
911
963
  isValid = true;
912
964
  return false;
@@ -1098,7 +1150,7 @@
1098
1150
  _past: function(form, field, rules, i, options) {
1099
1151
 
1100
1152
  var p=rules[i + 1];
1101
- var fieldAlt = $(form.find("input[name='" + p.replace(/^#+/, '') + "']"));
1153
+ var fieldAlt = $(form.find("*[name='" + p.replace(/^#+/, '') + "']"));
1102
1154
  var pdate;
1103
1155
 
1104
1156
  if (p.toLowerCase() == "now") {
@@ -1131,7 +1183,7 @@
1131
1183
  _future: function(form, field, rules, i, options) {
1132
1184
 
1133
1185
  var p=rules[i + 1];
1134
- var fieldAlt = $(form.find("input[name='" + p.replace(/^#+/, '') + "']"));
1186
+ var fieldAlt = $(form.find("*[name='" + p.replace(/^#+/, '') + "']"));
1135
1187
  var pdate;
1136
1188
 
1137
1189
  if (p.toLowerCase() == "now") {
@@ -1333,7 +1385,7 @@
1333
1385
  for (var i = 0; i < domIds.length; i++) {
1334
1386
  var id = domIds[i];
1335
1387
  if ($(id).length) {
1336
- var inputValue = field.closest("form").find(id).val();
1388
+ var inputValue = field.closest("form, .validationEngineContainer").find(id).val();
1337
1389
  var keyValue = id.replace('#', '') + '=' + escape(inputValue);
1338
1390
  data[id.replace('#', '')] = inputValue;
1339
1391
  }
@@ -1359,7 +1411,11 @@
1359
1411
  options: options,
1360
1412
  beforeSend: function() {},
1361
1413
  error: function(data, transport) {
1362
- methods._ajaxError(data, transport);
1414
+ if (options.onFailure) {
1415
+ options.onFailure(data, transport);
1416
+ } else {
1417
+ methods._ajaxError(data, transport);
1418
+ }
1363
1419
  },
1364
1420
  success: function(json) {
1365
1421
 
@@ -1455,6 +1511,10 @@
1455
1511
  var dateParts = d.split("-");
1456
1512
  if(dateParts==d)
1457
1513
  dateParts = d.split("/");
1514
+ if(dateParts==d) {
1515
+ dateParts = d.split(".");
1516
+ return new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
1517
+ }
1458
1518
  return new Date(dateParts[0], (dateParts[1] - 1) ,dateParts[2]);
1459
1519
  },
1460
1520
  /**
@@ -1467,6 +1527,13 @@
1467
1527
  * @param {Map} options user options
1468
1528
  */
1469
1529
  _showPrompt: function(field, promptText, type, ajaxed, options, ajaxform) {
1530
+ //Check if we need to adjust what element to show the prompt on
1531
+ if(field.data('jqv-prompt-at') instanceof jQuery ){
1532
+ field = field.data('jqv-prompt-at');
1533
+ } else if(field.data('jqv-prompt-at')) {
1534
+ field = $(field.data('jqv-prompt-at'));
1535
+ }
1536
+
1470
1537
  var prompt = methods._getPrompt(field);
1471
1538
  // The ajax submit errors are not see has an error in the form,
1472
1539
  // When the form errors are returned, the engine see 2 bubbles, but those are ebing closed by the engine at the same time
@@ -1495,7 +1562,7 @@
1495
1562
  var prompt = $('<div>');
1496
1563
  prompt.addClass(methods._getClassName(field.attr("id")) + "formError");
1497
1564
  // add a class name to identify the parent form of the prompt
1498
- prompt.addClass("parentForm"+methods._getClassName(field.parents('form').attr("id")));
1565
+ prompt.addClass("parentForm"+methods._getClassName(field.closest('form, .validationEngineContainer').attr("id")));
1499
1566
  prompt.addClass("formError");
1500
1567
 
1501
1568
  switch (type) {
@@ -1514,13 +1581,16 @@
1514
1581
 
1515
1582
  // create the prompt content
1516
1583
  var promptContent = $('<div>').addClass("formErrorContent").html(promptText).appendTo(prompt);
1584
+
1585
+ // determine position type
1586
+ var positionType=field.data("promptPosition") || options.promptPosition;
1587
+
1517
1588
  // create the css arrow pointing at the field
1518
1589
  // note that there is no triangle on max-checkbox and radio
1519
1590
  if (options.showArrow) {
1520
1591
  var arrow = $('<div>').addClass("formErrorArrow");
1521
1592
 
1522
1593
  //prompt positioning adjustment support. Usage: positionType:Xshift,Yshift (for ex.: bottomLeft:+20 or bottomLeft:-20,+10)
1523
- var positionType=field.data("promptPosition") || options.promptPosition;
1524
1594
  if (typeof(positionType)=='string')
1525
1595
  {
1526
1596
  var pos=positionType.indexOf(":");
@@ -1545,19 +1615,44 @@
1545
1615
  if (options.addPromptClass)
1546
1616
  prompt.addClass(options.addPromptClass);
1547
1617
 
1618
+ // Add custom prompt class defined in element
1619
+ var requiredOverride = field.attr('data-required-class');
1620
+ if(requiredOverride !== undefined) {
1621
+ prompt.addClass(requiredOverride);
1622
+ } else {
1623
+ if(options.prettySelect) {
1624
+ if($('#' + field.attr('id')).next().is('select')) {
1625
+ var prettyOverrideClass = $('#' + field.attr('id').substr(options.usePrefix.length).substring(options.useSuffix.length)).attr('data-required-class');
1626
+ if(prettyOverrideClass !== undefined) {
1627
+ prompt.addClass(prettyOverrideClass);
1628
+ }
1629
+ }
1630
+ }
1631
+ }
1632
+
1548
1633
  prompt.css({
1549
- "opacity": 0,
1550
- 'position':'absolute'
1634
+ "opacity": 0
1551
1635
  });
1552
- field.before(prompt);
1636
+ if(positionType === 'inline') {
1637
+ prompt.addClass("inline");
1638
+ if(typeof field.attr('data-prompt-target') !== 'undefined' && $('#'+field.attr('data-prompt-target')).length > 0) {
1639
+ prompt.appendTo($('#'+field.attr('data-prompt-target')));
1640
+ } else {
1641
+ field.after(prompt);
1642
+ }
1643
+ } else {
1644
+ field.before(prompt);
1645
+ }
1553
1646
 
1554
1647
  var pos = methods._calculatePosition(field, prompt, options);
1555
1648
  prompt.css({
1649
+ 'position': positionType === 'inline' ? 'relative' : 'absolute',
1556
1650
  "top": pos.callerTopPosition,
1557
1651
  "left": pos.callerleftPosition,
1558
1652
  "marginTop": pos.marginTopSize,
1559
1653
  "opacity": 0
1560
1654
  }).data("callerField", field);
1655
+
1561
1656
 
1562
1657
  if (options.autoHidePrompt) {
1563
1658
  setTimeout(function(){
@@ -1638,9 +1733,9 @@
1638
1733
  * @return undefined or the error prompt (jqObject)
1639
1734
  */
1640
1735
  _getPrompt: function(field) {
1641
- var formId = $(field).closest('form').attr('id');
1736
+ var formId = $(field).closest('form, .validationEngineContainer').attr('id');
1642
1737
  var className = methods._getClassName(field.attr("id")) + "formError";
1643
- var match = $("." + methods._escapeExpression(className) + '.parentForm' + formId)[0];
1738
+ var match = $("." + methods._escapeExpression(className) + '.parentForm' + methods._getClassName(formId))[0];
1644
1739
  if (match)
1645
1740
  return $(match);
1646
1741
  },
@@ -1767,6 +1862,11 @@
1767
1862
  promptleftPosition = fieldLeft + fieldWidth - 30;
1768
1863
  promptTopPosition = fieldTop + field.height() + 5;
1769
1864
  marginTopSize = 0;
1865
+ break;
1866
+ case "inline":
1867
+ promptleftPosition = 0;
1868
+ promptTopPosition = 0;
1869
+ marginTopSize = 0;
1770
1870
  };
1771
1871
 
1772
1872
 
@@ -1850,7 +1950,13 @@
1850
1950
  return methods._required(field, ["required"], 0, options);
1851
1951
  }
1852
1952
  }
1853
- }
1953
+ },
1954
+
1955
+ _submitButtonClick: function(event) {
1956
+ var button = $(this);
1957
+ var form = button.closest('form, .validationEngineContainer');
1958
+ form.data("jqv_submitButton", button.attr("id"));
1959
+ }
1854
1960
  };
1855
1961
 
1856
1962
  /**
@@ -1897,8 +2003,11 @@
1897
2003
  focusFirstField:true,
1898
2004
  // Show prompts, set to false to disable prompts
1899
2005
  showPrompts: true,
2006
+ // Should we attempt to validate non-visible input fields contained in the form? (Useful in cases of tabbed containers, e.g. jQuery-UI tabs)
2007
+ validateNonVisibleFields: false,
1900
2008
  // Opening box position, possible locations are: topLeft,
1901
- // topRight, bottomLeft, centerRight, bottomRight
2009
+ // topRight, bottomLeft, centerRight, bottomRight, inline
2010
+ // inline gets inserted after the validated field or into an element specified in data-prompt-target
1902
2011
  promptPosition: "topRight",
1903
2012
  bindMethod:"bind",
1904
2013
  // internal, automatically set to true when it parse a _ajax rule
@@ -1942,8 +2051,8 @@
1942
2051
  onSuccess: false,
1943
2052
  onFailure: false,
1944
2053
  validateAttribute: "class",
1945
- addSuccessCssClassToField: false,
1946
- addFailureCssClassToField: false,
2054
+ addSuccessCssClassToField: "",
2055
+ addFailureCssClassToField: "",
1947
2056
 
1948
2057
  // Auto-hide prompt
1949
2058
  autoHidePrompt: false,
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jQuery-Validation-Engine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - qichunren
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-29 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: jQuery-Validation-Engine jquery plugin for rails project.
15
14
  email:
@@ -33,27 +32,26 @@ files:
33
32
  - vendor/assets/stylesheets/validationEngine.jquery.css.scss
34
33
  homepage: https://github.com/qichunren/jQuery-Validation-Engine-rails
35
34
  licenses: []
35
+ metadata: {}
36
36
  post_install_message:
37
37
  rdoc_options: []
38
38
  require_paths:
39
39
  - lib
40
40
  required_ruby_version: !ruby/object:Gem::Requirement
41
- none: false
42
41
  requirements:
43
42
  - - ! '>='
44
43
  - !ruby/object:Gem::Version
45
44
  version: '0'
46
45
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
46
  requirements:
49
47
  - - ! '>='
50
48
  - !ruby/object:Gem::Version
51
49
  version: '0'
52
50
  requirements: []
53
51
  rubyforge_project:
54
- rubygems_version: 1.8.24
52
+ rubygems_version: 2.0.3
55
53
  signing_key:
56
- specification_version: 3
54
+ specification_version: 4
57
55
  summary: jQuery-Validation-Engine jquery plugin for rails project.
58
56
  test_files: []
59
57
  has_rdoc: