autonumeric-rails 1.9.18.0 → 1.9.18.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ # 1.9.18.1
2
+
3
+ - Improved support for dynamically generated DOM elements
4
+
1
5
  # 1.9.18.0
2
6
 
3
7
  - Update autoNumeric v 1.9.18
data/README.md CHANGED
@@ -44,15 +44,20 @@ You can also pass autoNumeric configuration parameters directly with a Hash in y
44
44
 
45
45
  See autoNumeric pages (links above) for all details on configuration and options
46
46
 
47
- ## Internal and compatibility
47
+ ## Dynamic fields (AJAX and friends)
48
+
49
+ When a new fields with autonumeric attributes are generated after the DOM is loaded, either created by JavaScript
50
+ function or resulting of an AJAX call, you must manually refresh in order to initialize those new fields.
51
+
52
+ To do so you must trigger the `refresh_autonumeric` event on `document` after you modified the DOM:
53
+
54
+ $(document).trigger('refresh_autonumeric');
55
+
56
+ ## Internal
48
57
 
49
58
  Autonumeric-rails creates in the DOM an hidden input with the same name as the text field.
50
59
  On each modification of the test field value, the hidden input is updated with the sanitized value.
51
60
  When validating the form the hidden form value is naturally sent to the server as it is located after the text field.
52
-
53
- I've tried to add support for dynamically generated fields (through AJAX or other JS functions)
54
- and seems to works OK. But it relies on DOM event "DOMNodeInserted" which seems not to be
55
- compatible with IE 8 and older.
56
61
 
57
62
  ## Contributing
58
63
 
@@ -1,5 +1,5 @@
1
1
  module Autonumeric
2
2
  module Rails
3
- VERSION = '1.9.18.0'
3
+ VERSION = '1.9.18.1'
4
4
  end
5
5
  end
@@ -12,5 +12,8 @@
12
12
  hidden.val('<%= @record.field1.to_s %>');
13
13
  <% end %>
14
14
  $('form').prepend(hidden);
15
+
16
+
17
+ $(document).trigger('refresh_autonumeric');
15
18
  });
16
19
  </script>
Binary file
@@ -32,12 +32,12 @@
32
32
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33
33
  * OTHER DEALINGS IN THE SOFTWARE.
34
34
  */
35
-
36
35
  var AutonumericRails;
37
36
 
38
37
  window.AutonumericRails = AutonumericRails = (function() {
39
38
  function AutonumericRails(field) {
40
39
  this.field = field;
40
+ this.field.data('autonumeric-initialized', true);
41
41
  this.create_hidden_field();
42
42
  this.init_autonumeric();
43
43
  this.sanitize_value();
@@ -63,15 +63,17 @@ window.AutonumericRails = AutonumericRails = (function() {
63
63
 
64
64
  })();
65
65
 
66
- jQuery(function() {
66
+ window.refresh_autonumeric = function() {
67
67
  $('input[data-autonumeric]').each(function() {
68
- new window.AutonumericRails($(this));
69
- });
70
- $(document).on('DOMNodeInserted', function(e) {
71
- var element;
72
- element = $(e.target);
73
- if (element.attr('data-autonumeric')) {
74
- new window.AutonumericRails(element);
68
+ if (!$(this).data('autonumeric-initialized')) {
69
+ new window.AutonumericRails($(this));
75
70
  }
76
71
  });
72
+ };
73
+
74
+ jQuery(function() {
75
+ refresh_autonumeric();
76
+ $(document).on('refresh_autonumeric', function() {
77
+ refresh_autonumeric();
78
+ });
77
79
  });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autonumeric-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.18.0
4
+ version: 1.9.18.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-27 00:00:00.000000000 Z
12
+ date: 2014-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails