freeform 1.0.4 → 1.0.5
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 +8 -8
- data/Gemfile.lock +1 -1
- data/lib/freeform/builder/builder_mixin.rb +8 -3
- data/lib/freeform/form/nested.rb +8 -8
- data/lib/freeform/form/property.rb +15 -9
- data/lib/freeform/form.rb +62 -12
- data/lib/freeform/version.rb +1 -1
- data/spec/acceptance_spec.rb +105 -4
- data/spec/behavior_spec.rb +48 -0
- data/spec/dummy/app/controllers/projects_controller.rb +8 -2
- data/spec/dummy/app/forms/task_form.rb +3 -2
- data/spec/dummy/app/views/projects/new.html.erb +2 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +27711 -0
- data/spec/javascript_spec.rb +1 -2
- data/vendor/assets/javascripts/jquery_freeform.js +10 -5
- metadata +4 -9
- data/spec/dummy/app/assets/javascripts/prototype.js +0 -6082
- data/spec/dummy/app/assets/javascripts/prototype_events_test.js +0 -20
- data/spec/dummy/app/views/projects/without_intermediate_inputs.html.erb +0 -11
- data/vendor/assets/javascripts/prototype_freeform.js +0 -69
@@ -1,20 +0,0 @@
|
|
1
|
-
document.observe('dom:loaded', function() {
|
2
|
-
var log = function(text) {
|
3
|
-
var p = new Element('p').update(text);
|
4
|
-
$('console').insert(p);
|
5
|
-
};
|
6
|
-
|
7
|
-
['Added', 'Removed'].forEach(function(action) {
|
8
|
-
document.observe('nested:field' + action, function(e) {
|
9
|
-
log(action + ' some field')
|
10
|
-
});
|
11
|
-
|
12
|
-
document.observe('nested:field' + action + ':tasks', function(e) {
|
13
|
-
log(action + ' task field')
|
14
|
-
});
|
15
|
-
|
16
|
-
document.observe('nested:field' + action + ':milestones', function(e) {
|
17
|
-
log(action + ' milestone field')
|
18
|
-
});
|
19
|
-
});
|
20
|
-
});
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<%= nested_form_for Project.new do |f| -%>
|
2
|
-
<%= f.fields_for :tasks do |tf| -%>
|
3
|
-
<%= tf.fields_for :milestones do |mf| %>
|
4
|
-
<%= mf.text_field :name %>
|
5
|
-
<%= mf.link_to_remove 'Remove milestone' %>
|
6
|
-
<% end %>
|
7
|
-
<%= tf.link_to_add 'Add new milestone', :milestones %>
|
8
|
-
<%= tf.link_to_remove 'Remove' %>
|
9
|
-
<% end -%>
|
10
|
-
<%= f.link_to_add 'Add new task', :tasks %>
|
11
|
-
<% end -%>
|
@@ -1,69 +0,0 @@
|
|
1
|
-
document.observe('click', function(e, el) {
|
2
|
-
if (el = e.findElement('form a.add_nested_form')) {
|
3
|
-
// Setup
|
4
|
-
var assoc = el.readAttribute('data-association'); // Name of child
|
5
|
-
var target = el.readAttribute('data-target');
|
6
|
-
var blueprint = $(el.readAttribute('data-blueprint-id'));
|
7
|
-
var content = blueprint.readAttribute('data-blueprint'); // Fields template
|
8
|
-
|
9
|
-
// Make the context correct by replacing <parents> with the generated ID
|
10
|
-
// of each of the parent objects
|
11
|
-
var context = (el.getOffsetParent('.fields').firstDescendant().readAttribute('name') || '').replace(/\[[a-z_]+\]$/, '');
|
12
|
-
|
13
|
-
// If the parent has no inputs we need to strip off the last pair
|
14
|
-
var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]'));
|
15
|
-
if (current) {
|
16
|
-
context = context.replace(new RegExp('\\[' + current[1] + '\\]\\[(new_)?\\d+\\]$'), '');
|
17
|
-
}
|
18
|
-
|
19
|
-
// context will be something like this for a brand new form:
|
20
|
-
// project[tasks_attributes][1255929127459][assignments_attributes][1255929128105]
|
21
|
-
// or for an edit form:
|
22
|
-
// project[tasks_attributes][0][assignments_attributes][1]
|
23
|
-
if(context) {
|
24
|
-
var parent_names = context.match(/[a-z_]+_attributes(?=\]\[(new_)?\d+\])/g) || [];
|
25
|
-
var parent_ids = context.match(/[0-9]+/g) || [];
|
26
|
-
|
27
|
-
for(i = 0; i < parent_names.length; i++) {
|
28
|
-
if(parent_ids[i]) {
|
29
|
-
content = content.replace(
|
30
|
-
new RegExp('(_' + parent_names[i] + ')_.+?_', 'g'),
|
31
|
-
'$1_' + parent_ids[i] + '_');
|
32
|
-
|
33
|
-
content = content.replace(
|
34
|
-
new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
|
35
|
-
'$1[' + parent_ids[i] + ']');
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
// Make a unique ID for the new child
|
41
|
-
var regexp = new RegExp('new_' + assoc, 'g');
|
42
|
-
var new_id = new Date().getTime();
|
43
|
-
content = content.replace(regexp, new_id);
|
44
|
-
|
45
|
-
var field;
|
46
|
-
if (target) {
|
47
|
-
field = $$(target)[0].insert(content);
|
48
|
-
} else {
|
49
|
-
field = el.insert({ before: content });
|
50
|
-
}
|
51
|
-
field.fire('nested:fieldAdded', {field: field});
|
52
|
-
field.fire('nested:fieldAdded:' + assoc, {field: field});
|
53
|
-
return false;
|
54
|
-
}
|
55
|
-
});
|
56
|
-
|
57
|
-
document.observe('click', function(e, el) {
|
58
|
-
if (el = e.findElement('form a.remove_nested_form')) {
|
59
|
-
var hidden_field = el.previous(0),
|
60
|
-
assoc = el.readAttribute('data-association'); // Name of child to be removed
|
61
|
-
if(hidden_field) {
|
62
|
-
hidden_field.value = '1';
|
63
|
-
}
|
64
|
-
var field = el.up('.fields').hide();
|
65
|
-
field.fire('nested:fieldRemoved', {field: field});
|
66
|
-
field.fire('nested:fieldRemoved:' + assoc, {field: field});
|
67
|
-
return false;
|
68
|
-
}
|
69
|
-
});
|