fieldable_form 0.0.1
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/MIT-LICENSE +20 -0
- data/README.md +51 -0
- data/Rakefile +40 -0
- data/app/exceptions/fieldable_form/cannot_initialize_abstract_class.rb +4 -0
- data/app/models/concerns/fieldable_form/validations.rb +32 -0
- data/app/models/fieldable_form/abstract_field.rb +48 -0
- data/app/models/fieldable_form/base_form.rb +12 -0
- data/app/models/fieldable_form/check_box.rb +25 -0
- data/app/models/fieldable_form/drop_down.rb +62 -0
- data/app/models/fieldable_form/text_field.rb +86 -0
- data/app/models/fieldable_form/validatable.rb +12 -0
- data/db/migrate/20130302181724_create_fieldable_forms.rb +13 -0
- data/db/migrate/20130302192001_create_fieldable_form_fields.rb +16 -0
- data/lib/fieldable_form/engine.rb +9 -0
- data/lib/fieldable_form/version.rb +3 -0
- data/lib/fieldable_form.rb +11 -0
- data/lib/generators/fieldable_form/bootstrap/USAGE +8 -0
- data/lib/generators/fieldable_form/bootstrap/bootstrap_generator.rb +41 -0
- data/lib/generators/fieldable_form/bootstrap/templates/fieldable_form.js.coffee +12 -0
- data/lib/generators/fieldable_form/bootstrap/templates/fieldable_form_helper.rb +24 -0
- data/lib/generators/fieldable_form/bootstrap/templates/form.rb +2 -0
- data/lib/generators/fieldable_form/bootstrap/templates/views/builder/_check_box.html.erb +9 -0
- data/lib/generators/fieldable_form/bootstrap/templates/views/builder/_drop_down.html.erb +18 -0
- data/lib/generators/fieldable_form/bootstrap/templates/views/builder/_fields.html.erb +9 -0
- data/lib/generators/fieldable_form/bootstrap/templates/views/builder/_text_field.html.erb +21 -0
- data/lib/generators/fieldable_form/bootstrap/templates/views/entry/_field.html.erb +4 -0
- data/lib/tasks/fieldable_form_tasks.rake +4 -0
- metadata +206 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Roy Yihang Bao
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
FieldableForm
|
2
|
+
==============
|
3
|
+
FieldableForm is intended to make building an end user facing form builder easier. It provides all the base models necessary for building such functionality and also some erb and js templates for bootstraping the views.
|
4
|
+
|
5
|
+
Installation
|
6
|
+
-------------
|
7
|
+
FieldableForm is only compatiable with Rails 3+.
|
8
|
+
|
9
|
+
gem 'fieldable_form'
|
10
|
+
|
11
|
+
Getting Started
|
12
|
+
----------
|
13
|
+
The best way get started with FieldableForm is by looking into the [Sample App](# "Sample App").
|
14
|
+
|
15
|
+
### Form Model
|
16
|
+
The core functionality of FieldableForm is provided by the base form model `FieldableForm::BaseForm`. It is recommanded that you do not use this model directly, instead you should build your own form model by inheriting from this class.
|
17
|
+
|
18
|
+
class ProductForm < FieldableForm::BaseForm
|
19
|
+
end
|
20
|
+
|
21
|
+
The form model is basically a container that holds all the fields of a form. You can deal with the individual fields by simply calling `#fields` which is just a `has_many` association defined in `FieldableForm::BaseForm`.
|
22
|
+
|
23
|
+
### Entry Model
|
24
|
+
The entry model is the model that will hold the values of the fields that user entered through the form. This model is not provided by FieldableForm and you should build it by yourself. However, it needs to have an attribute which can holds the field name and value pairs as an hash.
|
25
|
+
|
26
|
+
class Product < ActiveRecord::Base
|
27
|
+
attr_accessible :product_form_id, :properties
|
28
|
+
belongs_to :product_form
|
29
|
+
|
30
|
+
# provides validations for the form field
|
31
|
+
include FieldableForm::Validations
|
32
|
+
validate_fieldable_form :product_form, :properties
|
33
|
+
|
34
|
+
serialize :properties, Hash
|
35
|
+
end
|
36
|
+
|
37
|
+
Then in the views you can use `OpenStruct` to render the fields from the `product_form` and its corresponding values.
|
38
|
+
|
39
|
+
<%= f.fields_for :properties, OpenStruct.new(@product.properties) do |ff| %>
|
40
|
+
<% @product.product_form.fields.each do |field| %>
|
41
|
+
<%= render "product_forms/entry/field", f: ff, field: field %>
|
42
|
+
<% end %>
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
Bootstrap Views
|
46
|
+
----------------
|
47
|
+
The FieldableForm gem itself only contains models and does not provide any views by default, since views will be much different for different applications. However you could get a default views and some useful helpers as a starting point.
|
48
|
+
|
49
|
+
rails g fieldable_form:boostrap
|
50
|
+
|
51
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'RealDynamicForm'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module FieldableForm
|
2
|
+
module Validations
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def validate_fieldable_form(form, values)
|
7
|
+
cattr_accessor :fieldable_form_getter_method, :fieldable_form_values_getter_method
|
8
|
+
self.fieldable_form_getter_method = form.to_sym
|
9
|
+
self.fieldable_form_values_getter_method = values.to_sym
|
10
|
+
|
11
|
+
validate :ensure_fieldable_form_valid
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def ensure_fieldable_form_valid
|
18
|
+
values = self.send(fieldable_form_values_getter_method)
|
19
|
+
validatable = Validatable.new(values)
|
20
|
+
|
21
|
+
self.send(fieldable_form_getter_method).fields.each do |field|
|
22
|
+
field.validators.each { |v| v.validate(validatable) }
|
23
|
+
end
|
24
|
+
|
25
|
+
validatable.errors.each do |k, msg|
|
26
|
+
errors.add(k, msg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module FieldableForm
|
2
|
+
class AbstractField < ActiveRecord::Base
|
3
|
+
|
4
|
+
DESCENDANTS = %w(FieldableForm::TextField FieldableForm::DropDown FieldableForm::CheckBox)
|
5
|
+
|
6
|
+
self.table_name = :fieldable_form_fields
|
7
|
+
|
8
|
+
attr_accessible :name, :options, :type
|
9
|
+
|
10
|
+
belongs_to :fieldable, :polymorphic => true, :touch => true
|
11
|
+
|
12
|
+
validates :name, :presence => true, :length => { :maximum => 255 }
|
13
|
+
validates :type, :presence => true, :inclusion => { :in => DESCENDANTS }
|
14
|
+
|
15
|
+
serialize :options, Hash
|
16
|
+
|
17
|
+
# Create the appropriate children instance according to the type.
|
18
|
+
def self.new(*args, &block)
|
19
|
+
# Children should use the original method
|
20
|
+
return super(*args, &block) if self != ::FieldableForm::AbstractField
|
21
|
+
|
22
|
+
attributes = args.first
|
23
|
+
raise CannotInitializeAbstractClass.new('FieldableForm::AbstractField is an abstract class') unless attributes.is_a?(Hash)
|
24
|
+
|
25
|
+
type = attributes[:type] || attributes['type']
|
26
|
+
return type.constantize.new(*args, &block) if DESCENDANTS.include?(type)
|
27
|
+
|
28
|
+
raise CannotInitializeAbstractClass.new('FieldableForm::AbstractField is an abstract class')
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_method
|
32
|
+
raise NotImplementedError('Subclass must implement this')
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_options
|
36
|
+
raise NotImplementedError('Subclass must implement this')
|
37
|
+
end
|
38
|
+
|
39
|
+
def view_partial_name
|
40
|
+
raise NotImplementedError('Subclass must implement this')
|
41
|
+
end
|
42
|
+
|
43
|
+
def validators
|
44
|
+
raise NotImplementedError('Subclass must implement this')
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module FieldableForm
|
2
|
+
class BaseForm < ActiveRecord::Base
|
3
|
+
self.table_name = :fieldable_forms
|
4
|
+
|
5
|
+
belongs_to :owner, :polymorphic => true
|
6
|
+
|
7
|
+
attr_accessible :fields_attributes
|
8
|
+
|
9
|
+
has_many :fields, :class_name => AbstractField, :as => :fieldable, :dependent => :destroy
|
10
|
+
accepts_nested_attributes_for :fields, :allow_destroy => true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module FieldableForm
|
2
|
+
class CheckBox < AbstractField
|
3
|
+
|
4
|
+
# Overrides
|
5
|
+
def render_method
|
6
|
+
:check_box
|
7
|
+
end
|
8
|
+
|
9
|
+
# Overrides
|
10
|
+
def render_options
|
11
|
+
[name]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Overrides
|
15
|
+
def view_partial_name
|
16
|
+
'check_box'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Overrides
|
20
|
+
def validators
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module FieldableForm
|
2
|
+
class DropDown < AbstractField
|
3
|
+
|
4
|
+
attr_accessible :required, :include_blank, :items
|
5
|
+
attr_accessor :required, :include_blank, :items
|
6
|
+
|
7
|
+
# Overrides
|
8
|
+
def render_method
|
9
|
+
:select
|
10
|
+
end
|
11
|
+
|
12
|
+
# Overrides
|
13
|
+
def render_options
|
14
|
+
items_array = items.squish.delete(' ').split(',')
|
15
|
+
if include_blank == '1'
|
16
|
+
items_array.map! { |i| [i, i] }
|
17
|
+
items_array.first[1] = nil
|
18
|
+
end
|
19
|
+
[name, items_array]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Overrides
|
23
|
+
def view_partial_name
|
24
|
+
'drop_down'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Overrides
|
28
|
+
def validators
|
29
|
+
validators = []
|
30
|
+
validators << ActiveModel::Validations::PresenceValidator.new(:attributes => name) if required == '1'
|
31
|
+
validators
|
32
|
+
end
|
33
|
+
|
34
|
+
def required
|
35
|
+
options['required']
|
36
|
+
end
|
37
|
+
|
38
|
+
def required=(value)
|
39
|
+
options_will_change! if options['required'] != value
|
40
|
+
options['required'] = value
|
41
|
+
end
|
42
|
+
|
43
|
+
def include_blank
|
44
|
+
options['include_blank']
|
45
|
+
end
|
46
|
+
|
47
|
+
def include_blank=(value)
|
48
|
+
options_will_change! if options['include_blank'] != value
|
49
|
+
options['include_blank'] = value
|
50
|
+
end
|
51
|
+
|
52
|
+
def items
|
53
|
+
options['items']
|
54
|
+
end
|
55
|
+
|
56
|
+
def items=(value)
|
57
|
+
options_will_change! if options['items'] != value
|
58
|
+
options['items'] = value
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module FieldableForm
|
2
|
+
class TextField < AbstractField
|
3
|
+
|
4
|
+
attr_accessible :required, :number_only, :min_length, :max_length
|
5
|
+
attr_accessor :required, :number_only, :min_length, :max_length
|
6
|
+
|
7
|
+
validates :min_length, :allow_blank => true, :numericality => { :only_integer => true }, :length => { :maximum => 255 }
|
8
|
+
validates :max_length, :allow_blank => true, :numericality => { :only_integer => true }, :length => { :maximum => 255 }
|
9
|
+
|
10
|
+
# Overrides
|
11
|
+
def render_method
|
12
|
+
:text_field
|
13
|
+
end
|
14
|
+
|
15
|
+
# Overrides
|
16
|
+
def render_options
|
17
|
+
[name]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Overrides
|
21
|
+
def view_partial_name
|
22
|
+
'text_field'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Overrides
|
26
|
+
def validators
|
27
|
+
min = integerize_or_nil(min_length)
|
28
|
+
max = integerize_or_nil(max_length)
|
29
|
+
|
30
|
+
validators = []
|
31
|
+
validators << ActiveModel::Validations::PresenceValidator.new(:attributes => name) if required == '1'
|
32
|
+
validators << ActiveModel::Validations::NumericalityValidator.new(:attributes => name, :only_integer => true) if number_only == '1'
|
33
|
+
validators << ActiveModel::Validations::LengthValidator.new(:attributes => name, :minimum => min ) if min
|
34
|
+
validators << ActiveModel::Validations::LengthValidator.new(:attributes => name, :maximum => max ) if max
|
35
|
+
validators
|
36
|
+
end
|
37
|
+
|
38
|
+
def required
|
39
|
+
options['required']
|
40
|
+
end
|
41
|
+
|
42
|
+
def required=(value)
|
43
|
+
options_will_change! if options['required'] != value
|
44
|
+
options['required'] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
def number_only
|
48
|
+
options['number_only']
|
49
|
+
end
|
50
|
+
|
51
|
+
def number_only=(value)
|
52
|
+
options_will_change! if options['number_only'] != value
|
53
|
+
options['number_only'] = value
|
54
|
+
end
|
55
|
+
|
56
|
+
def min_length
|
57
|
+
options['min_length']
|
58
|
+
end
|
59
|
+
|
60
|
+
def min_length=(value)
|
61
|
+
options_will_change! if options['min_length'] != value
|
62
|
+
options['min_length'] = value
|
63
|
+
end
|
64
|
+
|
65
|
+
def max_length
|
66
|
+
options['max_length']
|
67
|
+
end
|
68
|
+
|
69
|
+
def max_length=(value)
|
70
|
+
options_will_change! if options['max_length'] != value
|
71
|
+
options['max_length'] = value
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def integerize_or_nil(str)
|
77
|
+
begin
|
78
|
+
result = Integer(str)
|
79
|
+
rescue ArgumentError, TypeError
|
80
|
+
result = nil
|
81
|
+
end
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateFieldableFormFields < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :fieldable_form_fields do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :type
|
6
|
+
t.text :options
|
7
|
+
|
8
|
+
t.integer :fieldable_id
|
9
|
+
t.string :fieldable_type
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :fieldable_form_fields, :fieldable_id
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module FieldableForm
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
config.autoload_paths << root.join('app', 'models', 'concerns')
|
4
|
+
|
5
|
+
initializer 'fieldable_form.add_migration_paths' do |app|
|
6
|
+
app.config.paths['db/migrate'] += FieldableForm::Engine.paths['db/migrate'].existent
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class FieldableForm::BootstrapGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
argument :form_name, :type => :string
|
4
|
+
|
5
|
+
def generate_models
|
6
|
+
template 'form.rb', "app/models/#{uname}.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate_assets
|
10
|
+
template 'fieldable_form.js.coffee', "app/assets/javascripts/#{uname}.js.coffee"
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_helpers
|
14
|
+
template 'fieldable_form_helper.rb', "app/helpers/#{uname}_helper.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_views
|
18
|
+
template 'views/builder/_text_field.html.erb', "app/views/#{pname}/builder/_text_field.html.erb"
|
19
|
+
template 'views/builder/_drop_down.html.erb', "app/views/#{pname}/builder/_drop_down.html.erb"
|
20
|
+
template 'views/builder/_check_box.html.erb', "app/views/#{pname}/builder/_check_box.html.erb"
|
21
|
+
template 'views/entry/_field.html.erb', "app/views/#{pname}/entry/_field.html.erb"
|
22
|
+
template 'views/builder/_fields.html.erb', "app/views/#{pname}/builder/_fields.html.erb"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def pname
|
27
|
+
uname.pluralize
|
28
|
+
end
|
29
|
+
|
30
|
+
def uname
|
31
|
+
form_name.underscore
|
32
|
+
end
|
33
|
+
|
34
|
+
def dname
|
35
|
+
uname.dasherize
|
36
|
+
end
|
37
|
+
|
38
|
+
def cname
|
39
|
+
form_name.camelize
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# mostly from http://railscasts.com/episodes/403-dynamic-forms
|
2
|
+
$(document).on 'click', "a[data-<%= dname %>='remove_field']", (event) ->
|
3
|
+
$(this).prev('input[type=hidden]').val('1')
|
4
|
+
$(this).closest('fieldset').hide()
|
5
|
+
event.preventDefault()
|
6
|
+
|
7
|
+
$(document).on 'click', "a[data-<%= dname %>='add_field']", (event) ->
|
8
|
+
time = new Date().getTime()
|
9
|
+
regexp = new RegExp($(this).data('id'), 'g')
|
10
|
+
target = $(this).data('target')
|
11
|
+
$(target).append($(this).data('fields').replace(regexp, time))
|
12
|
+
event.preventDefault()
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module <%= cname %>Helper
|
2
|
+
|
3
|
+
# @param [ActionView::Helpers::FormBuilder] f The rails form builder object.
|
4
|
+
# @param [String, Symbol] field_type The field type, currently can only be :text_field, :drop_down or :check_box.
|
5
|
+
# @param [String] partial The partial to render when a field is added.
|
6
|
+
# @param [Hash] html_options The html options for the <a> tag. This options will be passed to the rails
|
7
|
+
# default link_to helper.
|
8
|
+
# @return a link with approriate data atrribute so that the right js will be hooked
|
9
|
+
# and when clicked will add a new field.
|
10
|
+
def <%= uname %>_add_field(f, name, field_type, target, partial, html_options = {})
|
11
|
+
partial ||= association.to_s.singularize + "_fields"
|
12
|
+
klass = "FieldableForm::#{field_type.to_s.camelize}".constantize
|
13
|
+
new_object = klass.new
|
14
|
+
|
15
|
+
id = new_object.object_id
|
16
|
+
fields = f.fields_for(:fields, new_object, child_index: id) do |builder|
|
17
|
+
render(partial, f: builder)
|
18
|
+
end
|
19
|
+
|
20
|
+
default = { data: { <%= uname %>: 'add_field', target: target, id: id, fields: fields.gsub("\n", "") } }
|
21
|
+
html_options = default.deep_merge(html_options)
|
22
|
+
link_to(name, '#', html_options)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<fieldset>
|
2
|
+
<%%= f.hidden_field :type, :value => 'FieldableForm::DropDown' %>
|
3
|
+
|
4
|
+
<%%= f.label :name %>
|
5
|
+
<%%= f.text_field :name %>
|
6
|
+
|
7
|
+
<%%= f.label :required %>
|
8
|
+
<%%= f.check_box :required %>
|
9
|
+
|
10
|
+
<%%= f.label :include_blank %>
|
11
|
+
<%%= f.check_box :include_blank %>
|
12
|
+
|
13
|
+
<%%= f.label :items %>
|
14
|
+
<%%= f.text_area :items %>
|
15
|
+
|
16
|
+
<%%= f.hidden_field :_destroy %>
|
17
|
+
<%%= link_to '[remove]', '#', data: { <%= uname %>: 'remove_field' } %>
|
18
|
+
</fieldset>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<div id="fields_section">
|
2
|
+
<%%= f.fields_for :fields do |ff| %>
|
3
|
+
<%%= render "<%= pname %>/builder/#{ff.object.type.demodulize.underscore}", f: ff %>
|
4
|
+
<%% end %>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<%%= <%= uname %>_add_field f, "Add Text Field", :text_field, '#fields_section', '<%= pname %>/builder/text_field' %>
|
8
|
+
<%%= <%= uname %>_add_field f, "Add Drop Down", :drop_down, '#fields_section', '<%= pname %>/builder/drop_down' %>
|
9
|
+
<%%= <%= uname %>_add_field f, "Add Check Box", :check_box, '#fields_section', '<%= pname %>/builder/check_box' %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<fieldset>
|
2
|
+
<%%= f.hidden_field :type, :value => 'FieldableForm::TextField' %>
|
3
|
+
|
4
|
+
<%%= f.label :name %>
|
5
|
+
<%%= f.text_field :name %>
|
6
|
+
|
7
|
+
<%%= f.label :required %>
|
8
|
+
<%%= f.check_box :required %>
|
9
|
+
|
10
|
+
<%%= f.label :number_only %>
|
11
|
+
<%%= f.check_box :number_only %>
|
12
|
+
|
13
|
+
<%%= f.label :min_length %>
|
14
|
+
<%%= f.text_field :min_length %>
|
15
|
+
|
16
|
+
<%%= f.label :max_length %>
|
17
|
+
<%%= f.text_field :max_length %>
|
18
|
+
|
19
|
+
<%%= f.hidden_field :_destroy %>
|
20
|
+
<%%= link_to '[remove]', '#', data: { <%= uname %>: 'remove_field' } %>
|
21
|
+
</fieldset>
|
metadata
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fieldable_form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Roy Y. Bao
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.12
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.12
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.2.1
|
38
|
+
name: coffee-rails
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.2.0
|
54
|
+
name: jquery-rails
|
55
|
+
prerelease: false
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.2.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.3.11
|
70
|
+
name: mysql2
|
71
|
+
prerelease: false
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.3.11
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
type: :development
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
name: rspec-rails
|
87
|
+
prerelease: false
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
type: :development
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
name: faker
|
103
|
+
prerelease: false
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
type: :development
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
name: factory_girl_rails
|
119
|
+
prerelease: false
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
type: :development
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
name: simplecov
|
135
|
+
prerelease: false
|
136
|
+
requirement: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: FieldableForm allows you easily build a end user facing form builder.
|
143
|
+
email:
|
144
|
+
- roybao2010@gmail.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- app/exceptions/fieldable_form/cannot_initialize_abstract_class.rb
|
150
|
+
- app/models/concerns/fieldable_form/validations.rb
|
151
|
+
- app/models/fieldable_form/abstract_field.rb
|
152
|
+
- app/models/fieldable_form/base_form.rb
|
153
|
+
- app/models/fieldable_form/check_box.rb
|
154
|
+
- app/models/fieldable_form/drop_down.rb
|
155
|
+
- app/models/fieldable_form/text_field.rb
|
156
|
+
- app/models/fieldable_form/validatable.rb
|
157
|
+
- db/migrate/20130302181724_create_fieldable_forms.rb
|
158
|
+
- db/migrate/20130302192001_create_fieldable_form_fields.rb
|
159
|
+
- lib/fieldable_form/engine.rb
|
160
|
+
- lib/fieldable_form/version.rb
|
161
|
+
- lib/fieldable_form.rb
|
162
|
+
- lib/generators/fieldable_form/bootstrap/bootstrap_generator.rb
|
163
|
+
- lib/generators/fieldable_form/bootstrap/templates/fieldable_form.js.coffee
|
164
|
+
- lib/generators/fieldable_form/bootstrap/templates/fieldable_form_helper.rb
|
165
|
+
- lib/generators/fieldable_form/bootstrap/templates/form.rb
|
166
|
+
- lib/generators/fieldable_form/bootstrap/templates/views/builder/_check_box.html.erb
|
167
|
+
- lib/generators/fieldable_form/bootstrap/templates/views/builder/_drop_down.html.erb
|
168
|
+
- lib/generators/fieldable_form/bootstrap/templates/views/builder/_fields.html.erb
|
169
|
+
- lib/generators/fieldable_form/bootstrap/templates/views/builder/_text_field.html.erb
|
170
|
+
- lib/generators/fieldable_form/bootstrap/templates/views/entry/_field.html.erb
|
171
|
+
- lib/generators/fieldable_form/bootstrap/USAGE
|
172
|
+
- lib/tasks/fieldable_form_tasks.rake
|
173
|
+
- MIT-LICENSE
|
174
|
+
- Rakefile
|
175
|
+
- README.md
|
176
|
+
homepage: https://github.com/rbao/fieldable_form
|
177
|
+
licenses: []
|
178
|
+
post_install_message:
|
179
|
+
rdoc_options: []
|
180
|
+
require_paths:
|
181
|
+
- lib
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
+
none: false
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
segments:
|
188
|
+
- 0
|
189
|
+
hash: -1153996208959128357
|
190
|
+
version: '0'
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
none: false
|
193
|
+
requirements:
|
194
|
+
- - ! '>='
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
segments:
|
197
|
+
- 0
|
198
|
+
hash: -1153996208959128357
|
199
|
+
version: '0'
|
200
|
+
requirements: []
|
201
|
+
rubyforge_project:
|
202
|
+
rubygems_version: 1.8.24
|
203
|
+
signing_key:
|
204
|
+
specification_version: 3
|
205
|
+
summary: FieldableForm allows you easily build a end user facing form builder.
|
206
|
+
test_files: []
|