rails_ajax_formhandler 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +22 -0
- data/lib/rails_ajax_formhandler/version.rb +1 -1
- data/vendor/assets/javascripts/ajax_formhandler.js +22 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b16d89a1cc885e39060f99cf45da8365b035e1c8
|
4
|
+
data.tar.gz: 3ba437a4d73b3d4438e0237c1d4392cf8a3d856a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e71402e8e855360087e61dfbba8cb98f7b489da9a4d52acc7f67210b9894b3db1d11fc429ab048b079cf7115052a844d19c951cff806c56ff633c859505e794
|
7
|
+
data.tar.gz: 3b7f81409edd07fb42c5135111289df16f35b5d6a6e096ebe3d440e7400e9d62a4ef79d14e13f466e572fd70f07e702607bd4511398b68d5cd34bb67d06f8b4a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -40,6 +40,10 @@ If you want to use built in validation-styles, add to your application.scss
|
|
40
40
|
|
41
41
|
## Usage
|
42
42
|
|
43
|
+
#Important
|
44
|
+
This works 'out of the box' with 'form_for'. Since Rails 5.1 the new 'form_with' is standard and 'form_for' will be removed completely removed in future releases. Until than,
|
45
|
+
the ajax_formhandler works with 'form_with' only with a little workaround, see below under "form_with". As soon as 'form_for' is completely removed, we'll come up with a new version, written explicitly for 'form_with'!
|
46
|
+
|
43
47
|
This works with standard generated scaffold controllers, models and views seamlessely!
|
44
48
|
Just add the following line to your js-file, for example 'client.js':
|
45
49
|
|
@@ -235,6 +239,24 @@ would look like
|
|
235
239
|
|
236
240
|
In this case please make sure that the hidden-input appears _after_ the 'dummy-field', like in the example above in order to render validation errors properly!
|
237
241
|
|
242
|
+
# Using with "form_with"
|
243
|
+
|
244
|
+
## in *_form.html.erb*
|
245
|
+
|
246
|
+
Adding an id , starting with "form_", ending with the modelname to the "form_with"- tag.
|
247
|
+
"form_with" doesn't add an id automatically, so you need to add an id in the same fashion:
|
248
|
+
`<modelname>_<fieldname>`
|
249
|
+
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
...
|
253
|
+
<%=form_with model: costumer_bill, id: "form_costumer_bill" do |form|%>
|
254
|
+
....
|
255
|
+
<%= form.text_field :name, id: "costumer_bill_name" %>
|
256
|
+
...
|
257
|
+
<% end %>
|
258
|
+
```
|
259
|
+
|
238
260
|
|
239
261
|
|
240
262
|
## Contributing and Support
|
@@ -193,7 +193,7 @@ PLEASE NOTE THAT VALIDATION-RENDERING NOT WORKING WITH NESTED ATTRIBUTES, AT LEA
|
|
193
193
|
|
194
194
|
*/
|
195
195
|
|
196
|
-
|
196
|
+
|
197
197
|
|
198
198
|
var FormHandler = function(options) {
|
199
199
|
var options = options || {};
|
@@ -206,7 +206,7 @@ PLEASE NOTE THAT VALIDATION-RENDERING NOT WORKING WITH NESTED ATTRIBUTES, AT LEA
|
|
206
206
|
|
207
207
|
|
208
208
|
FormHandler.prototype.filter_form_name = function(form_id) {
|
209
|
-
var form_name,form_name_parts = form_id.replace(/(new_|edit_)/g, '').split('_');
|
209
|
+
var form_name,form_name_parts = form_id.replace(/(new_|edit_|form_)/g, '').split('_');
|
210
210
|
var last_part = form_name_parts[form_name_parts.length -1]
|
211
211
|
if(isNaN(parseInt(last_part))){
|
212
212
|
form_name = form_name_parts.join("_")
|
@@ -232,11 +232,16 @@ PLEASE NOTE THAT VALIDATION-RENDERING NOT WORKING WITH NESTED ATTRIBUTES, AT LEA
|
|
232
232
|
var global_defaults = this.global_defaults;
|
233
233
|
var count = 0;
|
234
234
|
$.each($('form'),function(index,form) {
|
235
|
-
|
235
|
+
if(form.id) {
|
236
236
|
var form_name = form_handler.filter_form_name(form.id);
|
237
|
-
var form_object = { id: form.id, ignore: false};
|
237
|
+
var form_object = { id: form.id, ignore: false, index: index};
|
238
238
|
$.extend(true,form_object,global_defaults);
|
239
239
|
form_objects[form_name] = form_object;
|
240
|
+
}
|
241
|
+
else {
|
242
|
+
console.error("Missing id on this form: the id must start with \"form_\" and end with the underscored modelname. Example: modelname is \"ClientHistory\" so the id must be \"form_client_history\". ")
|
243
|
+
return false;
|
244
|
+
}
|
240
245
|
|
241
246
|
})
|
242
247
|
return form_objects;
|
@@ -244,15 +249,19 @@ PLEASE NOTE THAT VALIDATION-RENDERING NOT WORKING WITH NESTED ATTRIBUTES, AT LEA
|
|
244
249
|
|
245
250
|
|
246
251
|
FormHandler.prototype.init = function() {
|
247
|
-
|
248
|
-
|
252
|
+
if(this.form_objects) {
|
253
|
+
var instances = {};
|
254
|
+
$.each(this.form_objects, function(name, settings) {
|
249
255
|
|
250
256
|
if(!settings.ignore) {
|
251
257
|
instances[name] = new FormObject(settings.id, settings);
|
252
258
|
instances[name].set_listener()
|
253
259
|
}
|
254
|
-
|
255
|
-
|
260
|
+
})
|
261
|
+
this.instances = instances;
|
262
|
+
} else {
|
263
|
+
return false
|
264
|
+
}
|
256
265
|
|
257
266
|
};
|
258
267
|
|
@@ -355,23 +364,10 @@ var FormObject = function(form_id, options) {
|
|
355
364
|
}
|
356
365
|
FormObject.prototype.set_form_type = function() {
|
357
366
|
var form = $("#" + this.form_id);
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
method = "PATCH"
|
363
|
-
this.form_object_name = to_array.slice(1,(to_array.length -1) ).join("_")
|
364
|
-
|
365
|
-
|
366
|
-
} else if(to_array[0] === "new") {
|
367
|
-
|
368
|
-
if(to_array.length > 2) {
|
369
|
-
this.form_object_name = to_array.slice(1,(to_array.length) ).join("_")
|
370
|
-
} else {
|
371
|
-
this.form_object_name = to_array[1]
|
372
|
-
}
|
373
|
-
|
374
|
-
}
|
367
|
+
if(form.find("input[name='_method']").length > 0) {
|
368
|
+
this.method = form.find("input[name='_method']").first().val();
|
369
|
+
}
|
370
|
+
this.form_object_name = this.form_id;
|
375
371
|
};
|
376
372
|
|
377
373
|
|
@@ -411,6 +407,7 @@ FormObject.prototype.get_ajax_settings = function(event,values) {
|
|
411
407
|
})
|
412
408
|
};
|
413
409
|
|
410
|
+
|
414
411
|
FormObject.prototype.set_redirections = function(redirections) {
|
415
412
|
var redirections = redirections || {};
|
416
413
|
var detected = {};
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_ajax_formhandler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Brancaccio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|