effective_form_inputs 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +101 -9
- data/app/assets/javascripts/effective_email/initialize.js.coffee +12 -0
- data/app/assets/javascripts/effective_email/input.js +1 -0
- data/app/assets/javascripts/effective_form_inputs.js +1 -0
- data/app/assets/javascripts/effective_price/initialize.js.coffee +1 -1
- data/app/assets/javascripts/effective_url/initialize.js.coffee +14 -0
- data/app/assets/javascripts/effective_url/input.js +1 -0
- data/app/models/inputs/effective_email/input.rb +28 -0
- data/app/models/inputs/effective_email_input.rb +12 -0
- data/app/models/inputs/effective_static_control/input.rb +6 -1
- data/app/models/inputs/effective_tel/input.rb +1 -1
- data/app/models/inputs/effective_url/input.rb +87 -0
- data/app/models/inputs/effective_url_input.rb +14 -0
- data/app/validators/effective_email_validator.rb +13 -0
- data/app/validators/effective_tel_validator.rb +13 -0
- data/app/validators/effective_url_validator.rb +13 -0
- data/lib/effective_form_inputs/version.rb +1 -1
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 060510deeb8a9fd2a79cfa4152a6c5b837a850a6
|
4
|
+
data.tar.gz: 4a9ef0428e0919592d6e29f536bb4797e469da9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdb69f861ed65d3719c731baf3bb938ced5ca64914ffad00c5f27bf0151bc553db4cd886e979d7423846b4f5650644b8022afd1de4f84df368ed7d577bed1134
|
7
|
+
data.tar.gz: 292e19a6587e521cdfe9db2852bc0d9a8a8d5789a1853176adf1379ba2a3cee6dc75fe566cdea65d4c527a7c1fb92d19bc366b239ce9dfd43d54b91c113ac71c
|
data/README.md
CHANGED
@@ -196,6 +196,54 @@ Use the following JavaScript to programatically set the date:
|
|
196
196
|
$('#start_at').data('DateTimePicker').date('2016-05-08')
|
197
197
|
```
|
198
198
|
|
199
|
+
## Effective Email
|
200
|
+
|
201
|
+
This custom form input makes sure the input is an email address.
|
202
|
+
|
203
|
+
### Installation
|
204
|
+
|
205
|
+
If you've already installed the 'All Form Inputs' assets (see above), there are no additional installation steps.
|
206
|
+
|
207
|
+
To install this form input individually, add the following to your application.js:
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
//= require effective_email/input
|
211
|
+
```
|
212
|
+
|
213
|
+
### Usage
|
214
|
+
|
215
|
+
As a Rails Form Helper input:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
= form_for @user do |f|
|
219
|
+
= f.effective_email :email
|
220
|
+
```
|
221
|
+
|
222
|
+
As a SimpleForm input:
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
= simple_form_for @user do |f|
|
226
|
+
= f.input :email, :as => :effective_email
|
227
|
+
```
|
228
|
+
|
229
|
+
As a SimpleForm input without the input group (envelope glyphicon)
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
= simple_form_for @user do |f|
|
233
|
+
= f.input :email, :as => :effective_email, :input_group => false
|
234
|
+
```
|
235
|
+
|
236
|
+
You should add a server side validation to enforce the format:
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
validates :email, format: { with: /\A.+@.+\..+\Z/ }
|
240
|
+
validates :email, effective_email: true # Enforces same format as above
|
241
|
+
```
|
242
|
+
|
243
|
+
### Options
|
244
|
+
|
245
|
+
There are no javascript options for this input.
|
246
|
+
|
199
247
|
## Effective Static Control
|
200
248
|
|
201
249
|
A bootstrap3 Static control input
|
@@ -397,12 +445,6 @@ To install this form input individually, add the following to your application.j
|
|
397
445
|
//= require effective_tel/input
|
398
446
|
```
|
399
447
|
|
400
|
-
and add the following to your application.css:
|
401
|
-
|
402
|
-
```ruby
|
403
|
-
*= require effective_tel/input
|
404
|
-
```
|
405
|
-
|
406
448
|
### Usage
|
407
449
|
|
408
450
|
As a Rails Form Helper input:
|
@@ -426,10 +468,11 @@ As a SimpleForm input without the input group (phone glyphicon)
|
|
426
468
|
= f.input :phone, :as => :effective_tel, :input_group => false
|
427
469
|
```
|
428
470
|
|
429
|
-
You
|
471
|
+
You should add a server side validation to enforce the default "(123) 555-1234" with optional "x123" extension format:
|
430
472
|
|
431
473
|
```ruby
|
432
474
|
validates :phone, format: { with: /\A\(\d{3}\) \d{3}-\d{4}( x\d+)?\Z/ }
|
475
|
+
validates :phone, effective_tel: true # Enforces same format as above
|
433
476
|
```
|
434
477
|
|
435
478
|
## Effective Price
|
@@ -482,14 +525,63 @@ You can pass `include_blank: true` to allow `nil`. By default `nil`s are conver
|
|
482
525
|
= f.input :price, :as => :effective_price, :include_blank => true
|
483
526
|
```
|
484
527
|
|
485
|
-
There are no javascript options for this input.
|
486
|
-
|
487
528
|
|
488
529
|
### Rails Helper
|
489
530
|
|
490
531
|
This input also installs a rails view helper `price_to_currency` that takes a value like `10000` and displays it as `$100.00`
|
491
532
|
|
492
533
|
|
534
|
+
## Effective URL
|
535
|
+
|
536
|
+
This custom form input enforces the url starts with http:// or https://
|
537
|
+
|
538
|
+
If font-awesome-rails gem is installed, a font-awesome icon for facebook, google, linkedin, twitter, vimeo and youtube will be inserted based on the field name.
|
539
|
+
|
540
|
+
### Installation
|
541
|
+
|
542
|
+
If you've already installed the 'All Form Inputs' assets (see above), there are no additional installation steps.
|
543
|
+
|
544
|
+
To install this form input individually, add the following to your application.js:
|
545
|
+
|
546
|
+
```ruby
|
547
|
+
//= require effective_url/input
|
548
|
+
```
|
549
|
+
|
550
|
+
### Usage
|
551
|
+
|
552
|
+
As a Rails Form Helper input:
|
553
|
+
|
554
|
+
```ruby
|
555
|
+
= form_for @user do |f|
|
556
|
+
= f.effective_url :website
|
557
|
+
```
|
558
|
+
|
559
|
+
As a SimpleForm input:
|
560
|
+
|
561
|
+
```ruby
|
562
|
+
= simple_form_for @user do |f|
|
563
|
+
= f.input :website, :as => :effective_url
|
564
|
+
```
|
565
|
+
|
566
|
+
As a SimpleForm input without the input group (globe glyphicon)
|
567
|
+
|
568
|
+
```ruby
|
569
|
+
= simple_form_for @user do |f|
|
570
|
+
= f.input :website, :as => :effective_url, :input_group => false
|
571
|
+
```
|
572
|
+
|
573
|
+
You should add a server side validation to enforce the url starts with http(s?)://
|
574
|
+
|
575
|
+
```ruby
|
576
|
+
validates :phone, format: { with: /\Ahttps?:\/\/\w+.+\Z/ }
|
577
|
+
validates :website, effective_url: true # Enforced same format as above
|
578
|
+
```
|
579
|
+
|
580
|
+
### Options
|
581
|
+
|
582
|
+
You can pass `fontawesome: false` and `glyphicon: false` to tweak the automatic social icon display behaviour.
|
583
|
+
|
584
|
+
|
493
585
|
## Effective CKEditor Text Area
|
494
586
|
|
495
587
|
This custom form input replaces a standard textarea with a CKEditor html rich text area.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
initialize = ->
|
2
|
+
$('input.effective_email:not(.initialized)').each (i, element) ->
|
3
|
+
element = $(element)
|
4
|
+
options = element.data('input-js-options') || {}
|
5
|
+
|
6
|
+
# We don't actually do anything with options
|
7
|
+
element.addClass('initialized')
|
8
|
+
|
9
|
+
$ -> initialize()
|
10
|
+
$(document).on 'page:change', -> initialize()
|
11
|
+
$(document).on 'turbolinks:load', -> initialize()
|
12
|
+
$(document).on 'cocoon:after-insert', -> initialize()
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require ./initialize
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# http://digitalbush.com/projects/masked-input-plugin/
|
2
|
+
|
3
|
+
initialize = ->
|
4
|
+
$('input.effective_url:not(.initialized)').each (i, element) ->
|
5
|
+
element = $(element)
|
6
|
+
options = element.data('input-js-options') || {}
|
7
|
+
|
8
|
+
# We don't actually do anything with options
|
9
|
+
element.addClass('initialized')
|
10
|
+
|
11
|
+
$ -> initialize()
|
12
|
+
$(document).on 'page:change', -> initialize()
|
13
|
+
$(document).on 'turbolinks:load', -> initialize()
|
14
|
+
$(document).on 'cocoon:after-insert', -> initialize()
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require ./initialize
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Inputs
|
2
|
+
module EffectiveEmail
|
3
|
+
class Input < Effective::FormInput
|
4
|
+
delegate :content_tag, :email_field_tag, :to => :@template
|
5
|
+
|
6
|
+
def default_input_html
|
7
|
+
{
|
8
|
+
class: 'effective_email email',
|
9
|
+
placeholder: 'someone@example.com',
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_html
|
14
|
+
if options[:input_group] == false
|
15
|
+
return email_field_tag(field_name, value, tag_options)
|
16
|
+
end
|
17
|
+
|
18
|
+
content_tag(:div, class: 'input-group') do
|
19
|
+
content_tag(:span, class: 'input-group-addon') do
|
20
|
+
content_tag(:i, '', class: 'glyphicon glyphicon-envelope').html_safe
|
21
|
+
end +
|
22
|
+
email_field_tag(field_name, value, tag_options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# = simple_form_for @thing do |f|
|
2
|
+
# = f.input :email, :as => :effective_email
|
3
|
+
|
4
|
+
if defined?(SimpleForm)
|
5
|
+
|
6
|
+
class EffectiveEmailInput < SimpleForm::Inputs::StringInput
|
7
|
+
def input(wrapper_options = nil)
|
8
|
+
Inputs::EffectiveEmail::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -8,7 +8,12 @@ module Inputs
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def to_html
|
11
|
-
|
11
|
+
if value.kind_of?(String) && value.start_with?('<p>') && value.end_with?('</p>')
|
12
|
+
content_tag(:p, value[3...-4].html_safe, tag_options)
|
13
|
+
else
|
14
|
+
content_tag(:p, (value.html_safe? ? value : value.to_s.html_safe), tag_options)
|
15
|
+
end
|
16
|
+
|
12
17
|
end
|
13
18
|
|
14
19
|
def html_options
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Inputs
|
2
|
+
module EffectiveUrl
|
3
|
+
class Input < Effective::FormInput
|
4
|
+
FA_FIELD_NAMES = ['facebook', 'google', 'linkedin', 'twitter', 'vimeo', 'youtube']
|
5
|
+
|
6
|
+
delegate :content_tag, :url_field_tag, :to => :@template
|
7
|
+
|
8
|
+
def default_input_html
|
9
|
+
{
|
10
|
+
class: 'effective_url url',
|
11
|
+
pattern: 'https?://[A-Za-z0-9]+.+',
|
12
|
+
placeholder: placeholder,
|
13
|
+
title: 'A URL starting with http:// or https://'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_html
|
18
|
+
if options[:input_group] == false
|
19
|
+
return url_field_tag(field_name, value, tag_options)
|
20
|
+
end
|
21
|
+
|
22
|
+
content_tag(:div, class: 'input-group') do
|
23
|
+
content_tag(:span, class: 'input-group-addon') do
|
24
|
+
glyphicon + fontawesome
|
25
|
+
end +
|
26
|
+
url_field_tag(field_name, value, tag_options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def placeholder
|
31
|
+
if field_name.include?('facebook')
|
32
|
+
'https://www.facebook.com/MyProfile'
|
33
|
+
elsif field_name.include?('google')
|
34
|
+
'https://plus.google.com/+MyProfile'
|
35
|
+
elsif field_name.include?('linkedin')
|
36
|
+
'https://www.linkedin.com/in/MyProfile'
|
37
|
+
elsif field_name.include?('twitter')
|
38
|
+
'https://twitter.com/MyProfile'
|
39
|
+
elsif field_name.include?('vimeo')
|
40
|
+
'https://vimeo.com/MyProfile'
|
41
|
+
elsif field_name.include?('youtube')
|
42
|
+
'https://www.youtube.com/user/MyProfile'
|
43
|
+
else
|
44
|
+
'http://www.example.com'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def glyphicon
|
49
|
+
if options[:glyphicon] == false
|
50
|
+
''.html_safe
|
51
|
+
elsif options[:glyphicon] == true
|
52
|
+
content_tag(:i, '', class: 'glyphicon glyphicon-globe')
|
53
|
+
elsif options[:glyphicon].present?
|
54
|
+
content_tag(:i, '', class: "glyphicon glyphicon-#{options[:glyphicon].to_s.gsub('glyphicon-', '')}")
|
55
|
+
elsif defined?(FontAwesome) && FA_FIELD_NAMES.any? { |name| field_name.include?(name) } && options[:fontawesome] != false
|
56
|
+
''.html_safe
|
57
|
+
else
|
58
|
+
content_tag(:i, '', class: 'glyphicon glyphicon-globe')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def fontawesome
|
63
|
+
if options[:fontawesome] == false
|
64
|
+
''.html_safe
|
65
|
+
elsif options[:fontawesome].present? && options[:fontawesome] != true
|
66
|
+
content_tag(:i, '', class: "fa fa-#{options[:fontawesome].to_s.gsub('fa-', '')}")
|
67
|
+
elsif field_name.include?('facebook')
|
68
|
+
content_tag(:i, '', class: 'fa fa-facebook')
|
69
|
+
elsif field_name.include?('google')
|
70
|
+
content_tag(:i, '', class: 'fa fa-google')
|
71
|
+
elsif field_name.include?('linkedin')
|
72
|
+
content_tag(:i, '', class: 'fa fa-linkedin')
|
73
|
+
elsif field_name.include?('twitter')
|
74
|
+
content_tag(:i, '', class: 'fa fa-twitter')
|
75
|
+
elsif field_name.include?('vimeo')
|
76
|
+
content_tag(:i, '', class: 'fa fa-vimeo')
|
77
|
+
elsif field_name.include?('youtube')
|
78
|
+
content_tag(:i, '', class: 'fa fa-youtube')
|
79
|
+
else
|
80
|
+
''.html_safe
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# = simple_form_for @thing do |f|
|
2
|
+
# = f.input :website, :as => :effective_url
|
3
|
+
# = f.input :website, :as => :effective_url, :glyphicon => false
|
4
|
+
# = f.input :website, :as => :effective_url, :fontawesome => false
|
5
|
+
|
6
|
+
if defined?(SimpleForm)
|
7
|
+
|
8
|
+
class EffectiveUrlInput < SimpleForm::Inputs::StringInput
|
9
|
+
def input(wrapper_options = nil)
|
10
|
+
Inputs::EffectiveUrl::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# An ActiveRecord validator for any email field that you would use with effective_email or otherwise
|
2
|
+
#
|
3
|
+
# validates :phone, effective_email: true
|
4
|
+
|
5
|
+
class EffectiveEmailValidator < ActiveModel::EachValidator
|
6
|
+
PATTERN = /\A.+@.+\..+\Z/
|
7
|
+
|
8
|
+
def validate_each(record, attribute, value)
|
9
|
+
if value.present?
|
10
|
+
record.errors.add(attribute, 'is invalid') unless PATTERN =~ value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# An ActiveRecord validator for any phone field that you would use with effective_tel
|
2
|
+
#
|
3
|
+
# validates :phone, effective_tel: true
|
4
|
+
|
5
|
+
class EffectiveTelValidator < ActiveModel::EachValidator
|
6
|
+
PATTERN = /\A\(\d{3}\) \d{3}-\d{4}( x\d+)?\Z/
|
7
|
+
|
8
|
+
def validate_each(record, attribute, value)
|
9
|
+
if value.present?
|
10
|
+
record.errors.add(attribute, 'is invalid') unless PATTERN =~ value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# An ActiveRecord validator for any url field that you would use with effective_url or otherwise
|
2
|
+
#
|
3
|
+
# validates :phone, effective_url: true
|
4
|
+
|
5
|
+
class EffectiveUrlValidator < ActiveModel::EachValidator
|
6
|
+
PATTERN = /\Ahttps?:\/\/\w+.+\Z/
|
7
|
+
|
8
|
+
def validate_each(record, attribute, value)
|
9
|
+
if value.present?
|
10
|
+
record.errors.add(attribute, 'is invalid') unless PATTERN =~ value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_form_inputs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -57,6 +57,8 @@ files:
|
|
57
57
|
- app/assets/javascripts/effective_date_time_picker/input.js
|
58
58
|
- app/assets/javascripts/effective_date_time_picker/moment.js
|
59
59
|
- app/assets/javascripts/effective_date_time_picker/overrides.js.coffee
|
60
|
+
- app/assets/javascripts/effective_email/initialize.js.coffee
|
61
|
+
- app/assets/javascripts/effective_email/input.js
|
60
62
|
- app/assets/javascripts/effective_form_inputs.js
|
61
63
|
- app/assets/javascripts/effective_price/initialize.js.coffee
|
62
64
|
- app/assets/javascripts/effective_price/input.js
|
@@ -67,6 +69,8 @@ files:
|
|
67
69
|
- app/assets/javascripts/effective_tel/initialize.js.coffee
|
68
70
|
- app/assets/javascripts/effective_tel/input.js
|
69
71
|
- app/assets/javascripts/effective_tel/jquery.maskedInput.js
|
72
|
+
- app/assets/javascripts/effective_url/initialize.js.coffee
|
73
|
+
- app/assets/javascripts/effective_url/input.js
|
70
74
|
- app/assets/stylesheets/effective_date_picker/input.scss
|
71
75
|
- app/assets/stylesheets/effective_date_time_picker/bootstrap-datetimepicker.scss
|
72
76
|
- app/assets/stylesheets/effective_date_time_picker/input.scss
|
@@ -85,6 +89,8 @@ files:
|
|
85
89
|
- app/models/inputs/effective_date_picker_input.rb
|
86
90
|
- app/models/inputs/effective_date_time_picker/input.rb
|
87
91
|
- app/models/inputs/effective_date_time_picker_input.rb
|
92
|
+
- app/models/inputs/effective_email/input.rb
|
93
|
+
- app/models/inputs/effective_email_input.rb
|
88
94
|
- app/models/inputs/effective_price/input.rb
|
89
95
|
- app/models/inputs/effective_price_input.rb
|
90
96
|
- app/models/inputs/effective_select/input.rb
|
@@ -93,6 +99,11 @@ files:
|
|
93
99
|
- app/models/inputs/effective_static_control_input.rb
|
94
100
|
- app/models/inputs/effective_tel/input.rb
|
95
101
|
- app/models/inputs/effective_tel_input.rb
|
102
|
+
- app/models/inputs/effective_url/input.rb
|
103
|
+
- app/models/inputs/effective_url_input.rb
|
104
|
+
- app/validators/effective_email_validator.rb
|
105
|
+
- app/validators/effective_tel_validator.rb
|
106
|
+
- app/validators/effective_url_validator.rb
|
96
107
|
- app/views/effective/style_guide/_effective_form_inputs.html.haml
|
97
108
|
- lib/effective_form_inputs.rb
|
98
109
|
- lib/effective_form_inputs/engine.rb
|