autonumeric-rails 1.9.21 → 1.9.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +6 -0
- data/README.md +10 -5
- data/lib/autonumeric/rails/version.rb +1 -1
- data/spec/autonumeric-rails_spec.rb +8 -3
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/forms_controller.rb +19 -6
- data/spec/dummy/app/views/forms/ajax_fields.html.erb +10 -0
- data/spec/dummy/app/views/forms/get_content_from_ajax.js.erb +1 -0
- data/spec/dummy/app/views/forms/javascript_fields.html.erb +18 -0
- data/spec/dummy/app/views/forms/{through_form_helper.html.erb → static_fields.html.erb} +0 -0
- data/spec/dummy/config/routes.rb +10 -4
- data/spec/support/{general.rb → wait_for_jquery.rb} +0 -0
- data/vendor/assets/javascripts/{autoNumeric-1.9.21.js → autoNumeric-1.9.22.js} +6 -7
- data/vendor/assets/javascripts/autonumeric.js +1 -1
- data/vendor/assets/javascripts/autonumeric_ujs.js +15 -7
- metadata +8 -11
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/forms/dynamic_field.html.erb +0 -19
- data/spec/dummy/lib/assets/.keep +0 -0
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 1.9.22
|
2
|
+
|
3
|
+
- Update autoNumeric v 1.9.22
|
4
|
+
- autoNumeric fields now automatically initialize after AJAX requests.
|
5
|
+
Manual DOM modification (through JavaScript) must still trigger `refresh_autonumeric` event manually
|
6
|
+
|
1
7
|
# 1.9.21
|
2
8
|
|
3
9
|
- Update autoNumeric v 1.9.21
|
data/README.md
CHANGED
@@ -44,10 +44,15 @@ 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
|
-
##
|
47
|
+
## AJAX
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
autonumeric-rails looks for `ajaxComplete` events which are trigger by jQuery every time an Ajax request finishes.
|
50
|
+
As a result, rails-ujs elements (i.e. `data-remote` elements) now automatically initialize autonumeric fields after the AJAX request is complete.
|
51
|
+
|
52
|
+
## Javascript DOM manipulation
|
53
|
+
|
54
|
+
When a Javascript function generate and add to the DOM new fields with autonumeric attributes,
|
55
|
+
you must manually refresh in order to initialize those new fields.
|
51
56
|
|
52
57
|
To do so you must trigger the `refresh_autonumeric` event on `document` after you modified the DOM:
|
53
58
|
|
@@ -56,8 +61,8 @@ To do so you must trigger the `refresh_autonumeric` event on `document` after yo
|
|
56
61
|
## Internal
|
57
62
|
|
58
63
|
Autonumeric-rails creates in the DOM an hidden input with the same name as the text field.
|
59
|
-
On each modification of the
|
60
|
-
When validating the form the hidden
|
64
|
+
On each modification of the text field value (through the `keyup` event), the hidden input is updated with the sanitized value.
|
65
|
+
When validating the form, the hidden field value is sent to the server as it is located after the text field in the DOM.
|
61
66
|
|
62
67
|
## Contributing
|
63
68
|
|
@@ -101,12 +101,17 @@ describe 'Autonumeric-rails', type: :feature, js: true do
|
|
101
101
|
before { wait_for_jquery }
|
102
102
|
|
103
103
|
context 'Through form helper' do
|
104
|
-
let(:url) { '
|
104
|
+
let(:url) { 'static_fields' }
|
105
105
|
it_behaves_like 'all autonumeric-rails tests'
|
106
106
|
end
|
107
107
|
|
108
|
-
context '
|
109
|
-
let(:url) { '
|
108
|
+
context 'Javascript manually created fields' do
|
109
|
+
let(:url) { 'javascript_fields' }
|
110
|
+
it_behaves_like 'all autonumeric-rails tests'
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'AJAX request created fields' do
|
114
|
+
let(:url) { 'ajax_fields' }
|
110
115
|
it_behaves_like 'all autonumeric-rails tests'
|
111
116
|
end
|
112
117
|
|
@@ -1,12 +1,25 @@
|
|
1
1
|
class FormsController < ApplicationController
|
2
|
-
create_action :through_form_helper
|
3
|
-
create_action :dynamic_field
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
create_action :static_fields
|
4
|
+
create_action :javascript_fields
|
5
|
+
create_action :get_content_from_ajax
|
6
|
+
|
7
|
+
def ajax_fields
|
8
|
+
@url_prefix = ''
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
10
|
-
@
|
11
|
+
def ajax_fields_with_record
|
12
|
+
@url_prefix = "/#{params[:id]}"
|
13
|
+
render action: :ajax_fields
|
11
14
|
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def without_record
|
19
|
+
@record = Record.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def with_record
|
23
|
+
@record = Record.find params[:id]
|
24
|
+
end
|
12
25
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
$("div#content").html("<%= j render template: 'forms/static_fields.html.erb' %>");
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%= form_for @record do |f| %>
|
2
|
+
<%= f.text_field :field2, data: {autonumeric: {aSign: 'USD ', mDec: 1}} %>
|
3
|
+
<%= f.submit 'Go' %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<script>
|
7
|
+
jQuery(function() {
|
8
|
+
var new_field;
|
9
|
+
new_field = $('<input>').attr('id', 'record_field1').attr('name', 'record[field1]');
|
10
|
+
new_field.attr('data-autonumeric', 'true').data('autonumeric', 'true');
|
11
|
+
<% if @record.field1 %>
|
12
|
+
new_field.val('<%= @record.field1.to_s %>');
|
13
|
+
<% end %>
|
14
|
+
$('form').prepend(new_field);
|
15
|
+
|
16
|
+
$(document).trigger('refresh_autonumeric');
|
17
|
+
});
|
18
|
+
</script>
|
File without changes
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
2
|
resources :records, only: [:create, :update]
|
3
3
|
|
4
|
-
get '/
|
5
|
-
get '/
|
4
|
+
get '/static_fields', to: 'forms#static_fields'
|
5
|
+
get '/static_fields/:id', to: 'forms#static_fields_with_record'
|
6
6
|
|
7
|
-
get '/
|
8
|
-
get '/
|
7
|
+
get '/javascript_fields', to: 'forms#javascript_fields'
|
8
|
+
get '/javascript_fields/:id', to: 'forms#javascript_fields_with_record'
|
9
|
+
|
10
|
+
get '/ajax_fields', to: 'forms#ajax_fields'
|
11
|
+
get '/ajax_fields/:id', to: 'forms#ajax_fields_with_record'
|
12
|
+
|
13
|
+
get '/get_content_from_ajax', to: 'forms#get_content_from_ajax'
|
14
|
+
get '/get_content_from_ajax/:id', to: 'forms#get_content_from_ajax_with_record'
|
9
15
|
end
|
File without changes
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* autoNumeric.js
|
3
3
|
* @author: Bob Knothe
|
4
4
|
* @author: Sokolov Yura
|
5
|
-
* @version: 1.9.
|
5
|
+
* @version: 1.9.22 - 2014-04-20 GMT 7:00 PM
|
6
6
|
*
|
7
7
|
* Created by Robert J. Knothe on 2010-10-25. Please report any bugs to https://github.com/BobKnothe/autoNumeric
|
8
8
|
* Created by Sokolov Yura on 2010-11-07
|
@@ -953,7 +953,6 @@
|
|
953
953
|
} else {
|
954
954
|
return this;
|
955
955
|
}
|
956
|
-
settings.lastSetValue = '';
|
957
956
|
settings.runOnce = false;
|
958
957
|
var holder = getHolder($this, settings);
|
959
958
|
if ($.inArray($this.prop('tagName'), settings.tagList) === -1 && $this.prop('tagName') !== 'INPUT') {
|
@@ -1154,21 +1153,21 @@
|
|
1154
1153
|
$.error("You must initialize autoNumeric('init', {options}) prior to calling the 'set' method");
|
1155
1154
|
return this;
|
1156
1155
|
}
|
1157
|
-
/** allows locale decimal separator to be a comma */
|
1158
|
-
if ((testValue === $this.attr('value') || testValue === $this.text()) && settings.runOnce === false) {
|
1159
|
-
value = value.replace(',', '.');
|
1160
|
-
}
|
1161
1156
|
/** routine to handle page re-load from back button */
|
1162
1157
|
if (testValue !== $this.attr('value') && $this.prop('tagName') === 'INPUT' && settings.runOnce === false) {
|
1158
|
+
value = (settings.nBracket !== null) ? negativeBracket($this.val(), settings.nBracket, 'pageLoad') : value;
|
1163
1159
|
value = autoStrip(value, settings);
|
1164
1160
|
}
|
1161
|
+
/** allows locale decimal separator to be a comma */
|
1162
|
+
if ((testValue === $this.attr('value') || testValue === $this.text()) && settings.runOnce === false) {
|
1163
|
+
value = value.replace(',', '.');
|
1164
|
+
}
|
1165
1165
|
/** returns a empty string if the value being 'set' contains non-numeric characters and or more than decimal point (full stop) and will not be formatted */
|
1166
1166
|
if (!$.isNumeric(+value)) {
|
1167
1167
|
return '';
|
1168
1168
|
}
|
1169
1169
|
value = checkValue(value, settings);
|
1170
1170
|
settings.oEvent = 'set';
|
1171
|
-
settings.lastSetValue = value; /** saves the unrounded value from the set method - $('selector').data('autoNumeric').lastSetValue; - helpful when you need to change the rounding accuracy*/
|
1172
1171
|
value.toString();
|
1173
1172
|
if (value !== '') {
|
1174
1173
|
value = autoRound(value, settings);
|
@@ -1,2 +1,2 @@
|
|
1
|
-
//= require autoNumeric-1.9.
|
1
|
+
//= require autoNumeric-1.9.22.js
|
2
2
|
//= require autonumeric_ujs.js
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* autonumeric_ujs.js
|
3
3
|
* @author: randoum
|
4
|
-
* @version: 1.9.
|
4
|
+
* @version: 1.9.22 - 2014-04-22
|
5
5
|
*
|
6
6
|
* Created by Randoum on 2013-08-15. Please report any bugs to https://github.com/randoum/autonumeric-rails
|
7
7
|
*
|
@@ -32,9 +32,16 @@
|
|
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
|
+
|
35
36
|
var AutonumericRails;
|
36
37
|
|
37
38
|
window.AutonumericRails = AutonumericRails = (function() {
|
39
|
+
AutonumericRails.create_autonumeric_object = function(obj) {
|
40
|
+
if (!obj.data('autonumeric-initialized')) {
|
41
|
+
return new this(obj);
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
38
45
|
function AutonumericRails(field) {
|
39
46
|
this.field = field;
|
40
47
|
this.field.data('autonumeric-initialized', true);
|
@@ -65,15 +72,16 @@ window.AutonumericRails = AutonumericRails = (function() {
|
|
65
72
|
|
66
73
|
window.refresh_autonumeric = function() {
|
67
74
|
$('input[data-autonumeric]').each(function() {
|
68
|
-
|
69
|
-
new window.AutonumericRails($(this));
|
70
|
-
}
|
75
|
+
AutonumericRails.create_autonumeric_object($(this));
|
71
76
|
});
|
72
77
|
};
|
73
78
|
|
74
79
|
jQuery(function() {
|
75
|
-
refresh_autonumeric();
|
80
|
+
window.refresh_autonumeric();
|
76
81
|
$(document).on('refresh_autonumeric', function() {
|
77
|
-
refresh_autonumeric();
|
82
|
+
window.refresh_autonumeric();
|
83
|
+
});
|
84
|
+
$(document).on('ajaxComplete', function() {
|
85
|
+
window.refresh_autonumeric();
|
78
86
|
});
|
79
|
-
});
|
87
|
+
});
|
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.
|
4
|
+
version: 1.9.22
|
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: 2014-04-
|
12
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jquery-rails
|
@@ -218,13 +218,11 @@ files:
|
|
218
218
|
- spec/dummy/app/controllers/concerns/.keep
|
219
219
|
- spec/dummy/app/controllers/forms_controller.rb
|
220
220
|
- spec/dummy/app/controllers/records_controller.rb
|
221
|
-
- spec/dummy/app/helpers/application_helper.rb
|
222
|
-
- spec/dummy/app/mailers/.keep
|
223
|
-
- spec/dummy/app/models/.keep
|
224
|
-
- spec/dummy/app/models/concerns/.keep
|
225
221
|
- spec/dummy/app/models/record.rb
|
226
|
-
- spec/dummy/app/views/forms/
|
227
|
-
- spec/dummy/app/views/forms/
|
222
|
+
- spec/dummy/app/views/forms/ajax_fields.html.erb
|
223
|
+
- spec/dummy/app/views/forms/get_content_from_ajax.js.erb
|
224
|
+
- spec/dummy/app/views/forms/javascript_fields.html.erb
|
225
|
+
- spec/dummy/app/views/forms/static_fields.html.erb
|
228
226
|
- spec/dummy/app/views/layouts/application.html.erb
|
229
227
|
- spec/dummy/bin/bundle
|
230
228
|
- spec/dummy/bin/rails
|
@@ -248,15 +246,14 @@ files:
|
|
248
246
|
- spec/dummy/config/routes.rb
|
249
247
|
- spec/dummy/db/migrate/20131227002328_create_records.rb
|
250
248
|
- spec/dummy/db/schema.rb
|
251
|
-
- spec/dummy/lib/assets/.keep
|
252
249
|
- spec/dummy/log/.keep
|
253
250
|
- spec/dummy/public/404.html
|
254
251
|
- spec/dummy/public/422.html
|
255
252
|
- spec/dummy/public/500.html
|
256
253
|
- spec/dummy/public/favicon.ico
|
257
254
|
- spec/spec_helper.rb
|
258
|
-
- spec/support/
|
259
|
-
- vendor/assets/javascripts/autoNumeric-1.9.
|
255
|
+
- spec/support/wait_for_jquery.rb
|
256
|
+
- vendor/assets/javascripts/autoNumeric-1.9.22.js
|
260
257
|
- vendor/assets/javascripts/autonumeric.js
|
261
258
|
- vendor/assets/javascripts/autonumeric_ujs.js
|
262
259
|
homepage: https://github.com/randoum/autonumeric-rails
|
File without changes
|
data/spec/dummy/app/models/.keep
DELETED
File without changes
|
File without changes
|
@@ -1,19 +0,0 @@
|
|
1
|
-
<%= form_for @record do |f| %>
|
2
|
-
<%= f.text_field :field2, data: {autonumeric: {aSign: 'USD ', mDec: 1}} %>
|
3
|
-
<%= f.submit 'Go' %>
|
4
|
-
<% end %>
|
5
|
-
|
6
|
-
<script>
|
7
|
-
jQuery(function() {
|
8
|
-
var hidden;
|
9
|
-
hidden = $('<input>').attr('id', 'record_field1').attr('name', 'record[field1]');
|
10
|
-
hidden.attr('data-autonumeric', 'true').data('autonumeric', 'true');
|
11
|
-
<% if @record.field1 %>
|
12
|
-
hidden.val('<%= @record.field1.to_s %>');
|
13
|
-
<% end %>
|
14
|
-
$('form').prepend(hidden);
|
15
|
-
|
16
|
-
|
17
|
-
$(document).trigger('refresh_autonumeric');
|
18
|
-
});
|
19
|
-
</script>
|
data/spec/dummy/lib/assets/.keep
DELETED
File without changes
|