effective_form_inputs 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +87 -17
- data/app/assets/javascripts/effective_form_inputs.js +1 -0
- data/app/assets/javascripts/effective_tel/initialize.js.coffee +15 -0
- data/app/assets/javascripts/effective_tel/input.js +2 -0
- data/app/assets/javascripts/effective_tel/jquery.maskedInput.js +182 -0
- data/app/models/effective/form_builder_inputs.rb +4 -2
- data/app/models/effective/form_input.rb +3 -0
- data/app/models/inputs/effective_date_picker/input.rb +8 -3
- data/app/models/inputs/effective_date_time_picker/input.rb +3 -3
- data/app/models/inputs/effective_tel/input.rb +45 -0
- data/app/models/inputs/effective_tel_input.rb +12 -0
- data/lib/effective_form_inputs/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e84a838832b598cc3b8261c04f468d304ae5d6ce
|
4
|
+
data.tar.gz: 9a1ce4d38760e24e0ff95a59db675cc94e98d97b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e357f9a67eb8ff7d33932117681d9552306db028835ec39fb71641b52ef2fd25431ea27f16582098a9e336c4c60df3b404ccca780c786672200501594b59669
|
7
|
+
data.tar.gz: 08f29d5e3bf603b181b3696519e7e4d67111598b1324be2592a8740bb0d3a97ebb43db5c9b803999a7dbc5c52fddc40a8abedd458b6b8c53df2b446d3b05514b
|
data/README.md
CHANGED
@@ -8,8 +8,6 @@ Each included form input is available to both the default Rails Form Helper and
|
|
8
8
|
|
9
9
|
Rails 3.2.x and 4.x
|
10
10
|
|
11
|
-
Right now there's just one form input. This will grow.
|
12
|
-
|
13
11
|
## Getting Started
|
14
12
|
|
15
13
|
Add to your Gemfile:
|
@@ -93,7 +91,7 @@ As a SimpleForm input without the input group (calendar glyphicon)
|
|
93
91
|
|
94
92
|
### Options
|
95
93
|
|
96
|
-
The default options used to initialize this form input are as follows:
|
94
|
+
The default `:input_js => options` used to initialize this form input are as follows:
|
97
95
|
|
98
96
|
```ruby
|
99
97
|
:input_js => {:format => 'YYYY-MM-DD h:mm A', :sideBySide => true}
|
@@ -152,7 +150,7 @@ As a SimpleForm input without the input group (calendar glyphicon)
|
|
152
150
|
|
153
151
|
### Options
|
154
152
|
|
155
|
-
The default options used to initialize this form input are as follows:
|
153
|
+
The default `:input_js => options` used to initialize this form input are as follows:
|
156
154
|
|
157
155
|
```ruby
|
158
156
|
:input_js => {:format => 'YYYY-MM-DD'}
|
@@ -191,7 +189,7 @@ As a SimpleForm input:
|
|
191
189
|
|
192
190
|
### Options
|
193
191
|
|
194
|
-
There are no options for this form input
|
192
|
+
There are no default options for this form input
|
195
193
|
|
196
194
|
|
197
195
|
## Effective Select
|
@@ -243,7 +241,7 @@ The standard mode is a replacement for the default single select box.
|
|
243
241
|
|
244
242
|
Passing `:multiple => true` will allow multiple selections to be made.
|
245
243
|
|
246
|
-
Passing `:multiple => true, :tags => true` will allow multiple selections to be made, and new value options to be created. This will allow you to select
|
244
|
+
Passing `:multiple => true, :tags => true` will allow multiple selections to be made, and new value options to be created. This will allow you to both select existing tags and create new tags in the same form control.
|
247
245
|
|
248
246
|
|
249
247
|
### Options
|
@@ -251,12 +249,14 @@ Passing `:multiple => true, :tags => true` will allow multiple selections to be
|
|
251
249
|
The default `:input_js => options` used to initialize this form input are as follows:
|
252
250
|
|
253
251
|
```ruby
|
254
|
-
|
255
|
-
:
|
256
|
-
:
|
257
|
-
:
|
258
|
-
:
|
259
|
-
:
|
252
|
+
{
|
253
|
+
:theme => 'bootstrap',
|
254
|
+
:minimumResultsForSearch => 6,
|
255
|
+
:tokenSeparators => [',', ' '],
|
256
|
+
:width => 'style',
|
257
|
+
:placeholder => 'Please choose',
|
258
|
+
:allowClear => !(options[:multiple]) # Only display the Clear 'x' on a single selection box
|
259
|
+
}
|
260
260
|
```
|
261
261
|
|
262
262
|
### Interesting Available Options
|
@@ -283,6 +283,79 @@ https://select2.github.io/options.html
|
|
283
283
|
There is currently no support for using AJAX to load remote data. This feature is supported by the underlying select2 library and will be implemented here at a future point.
|
284
284
|
|
285
285
|
|
286
|
+
## Effective Tel(ephone)
|
287
|
+
|
288
|
+
This custom form input uses a jQuery maskedInput plugin from the following awesome project:
|
289
|
+
|
290
|
+
http://digitalbush.com/projects/masked-input-plugin/
|
291
|
+
|
292
|
+
https://github.com/digitalBush/jquery.maskedinput
|
293
|
+
|
294
|
+
|
295
|
+
### Installation
|
296
|
+
|
297
|
+
If you've already installed the 'All Form Inputs' assets (see above), there are no additional installation steps.
|
298
|
+
|
299
|
+
To install this form input individually, add the following to your application.js:
|
300
|
+
|
301
|
+
```ruby
|
302
|
+
//= require effective_tel/input
|
303
|
+
```
|
304
|
+
|
305
|
+
and add the following to your application.css:
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
*= require effective_tel/input
|
309
|
+
```
|
310
|
+
|
311
|
+
### Usage
|
312
|
+
|
313
|
+
As a Rails Form Helper input:
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
= form_for @user do |f|
|
317
|
+
= f.effective_tel :phone
|
318
|
+
```
|
319
|
+
|
320
|
+
As a SimpleForm input:
|
321
|
+
|
322
|
+
```ruby
|
323
|
+
= simple_form_for @user do |f|
|
324
|
+
= f.input :phone, :as => :effective_tel
|
325
|
+
```
|
326
|
+
|
327
|
+
As a SimpleForm input without the input group (phone glyphicon)
|
328
|
+
|
329
|
+
```ruby
|
330
|
+
= simple_form_for @user do |f|
|
331
|
+
= f.input :phone, :as => :effective_tel, :input_group => false
|
332
|
+
```
|
333
|
+
|
334
|
+
### Options
|
335
|
+
|
336
|
+
By default, this form input uses the `glyphicon-earphone` glyphicon and accepts a telephone number with optional 5-digit extension.
|
337
|
+
|
338
|
+
It will set up a mask as follows:
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
:input_js => {:mask => '(999) 999-9999? x99999'}
|
342
|
+
```
|
343
|
+
|
344
|
+
Calling the form input with `:cellphone => true` will use the `glyphicon-phone` glyphicon and accept only a telephone number.
|
345
|
+
|
346
|
+
It will set up a mask as follows:
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
:input_js => {:mask => '(999) 999-9999'}
|
350
|
+
```
|
351
|
+
|
352
|
+
The only available javascript options are `mask` and `placeholder`:
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
:input_js => {:mask => '...', :placeholder => '_'}
|
356
|
+
```
|
357
|
+
|
358
|
+
|
286
359
|
## Passing Options to JavaScript
|
287
360
|
|
288
361
|
All `:input_js => options` passed to any effective_form_input will be used to initialize the Javascript library
|
@@ -309,8 +382,6 @@ $('input.effective_date_time_picker').datetimepicker
|
|
309
382
|
showTodayButton: true
|
310
383
|
```
|
311
384
|
|
312
|
-
Any option not recognized as a Rails Form Helper or SimpleForm option will be passed in this way to Javascript.
|
313
|
-
|
314
385
|
## License
|
315
386
|
|
316
387
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
@@ -320,9 +391,9 @@ Code and Effect is the product arm of [AgileStyle](http://www.agilestyle.com/),
|
|
320
391
|
|
321
392
|
## Credits
|
322
393
|
|
323
|
-
The authors of this gem are not associated with any of the awesome projects used
|
394
|
+
The authors of this gem are not associated with any of the awesome projects used by this gem.
|
324
395
|
|
325
|
-
We are just extending these existing community projects for ease of use with Rails Form Helper and SimpleForm
|
396
|
+
We are just extending these existing community projects for ease of use with Rails Form Helper and SimpleForm.
|
326
397
|
|
327
398
|
|
328
399
|
## Contributing
|
@@ -333,4 +404,3 @@ We are just extending these existing community projects for ease of use with Rai
|
|
333
404
|
4. Push to the branch (`git push origin my-new-feature`)
|
334
405
|
5. Bonus points for test coverage
|
335
406
|
6. Create new Pull Request
|
336
|
-
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# http://digitalbush.com/projects/masked-input-plugin/
|
2
|
+
|
3
|
+
initialize = ->
|
4
|
+
$('input.effective_tel:not(.initialized)').each (i, element) ->
|
5
|
+
element = $(element)
|
6
|
+
options = element.data('input-js-options') || {}
|
7
|
+
|
8
|
+
mask = options['mask']
|
9
|
+
delete options['mask']
|
10
|
+
|
11
|
+
element.addClass('initialized').mask(mask, options)
|
12
|
+
|
13
|
+
$ -> initialize()
|
14
|
+
$(document).on 'page:change', -> initialize()
|
15
|
+
$(document).on 'cocoon:after-insert', -> initialize()
|
@@ -0,0 +1,182 @@
|
|
1
|
+
/*
|
2
|
+
jQuery Masked Input Plugin
|
3
|
+
Copyright (c) 2007 - 2014 Josh Bush (digitalbush.com)
|
4
|
+
Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
|
5
|
+
Version: 1.4.0
|
6
|
+
*/
|
7
|
+
!function(factory) {
|
8
|
+
"function" == typeof define && define.amd ? define([ "jquery" ], factory) : factory("object" == typeof exports ? require("jquery") : jQuery);
|
9
|
+
}(function($) {
|
10
|
+
var caretTimeoutId, ua = navigator.userAgent, iPhone = /iphone/i.test(ua), chrome = /chrome/i.test(ua), android = /android/i.test(ua);
|
11
|
+
$.mask = {
|
12
|
+
definitions: {
|
13
|
+
"9": "[0-9]",
|
14
|
+
a: "[A-Za-z]",
|
15
|
+
"*": "[A-Za-z0-9]"
|
16
|
+
},
|
17
|
+
autoclear: !0,
|
18
|
+
dataName: "rawMaskFn",
|
19
|
+
placeholder: "_"
|
20
|
+
}, $.fn.extend({
|
21
|
+
caret: function(begin, end) {
|
22
|
+
var range;
|
23
|
+
if (0 !== this.length && !this.is(":hidden")) return "number" == typeof begin ? (end = "number" == typeof end ? end : begin,
|
24
|
+
this.each(function() {
|
25
|
+
this.setSelectionRange ? this.setSelectionRange(begin, end) : this.createTextRange && (range = this.createTextRange(),
|
26
|
+
range.collapse(!0), range.moveEnd("character", end), range.moveStart("character", begin),
|
27
|
+
range.select());
|
28
|
+
})) : (this[0].setSelectionRange ? (begin = this[0].selectionStart, end = this[0].selectionEnd) : document.selection && document.selection.createRange && (range = document.selection.createRange(),
|
29
|
+
begin = 0 - range.duplicate().moveStart("character", -1e5), end = begin + range.text.length),
|
30
|
+
{
|
31
|
+
begin: begin,
|
32
|
+
end: end
|
33
|
+
});
|
34
|
+
},
|
35
|
+
unmask: function() {
|
36
|
+
return this.trigger("unmask");
|
37
|
+
},
|
38
|
+
mask: function(mask, settings) {
|
39
|
+
var input, defs, tests, partialPosition, firstNonMaskPos, lastRequiredNonMaskPos, len, oldVal;
|
40
|
+
if (!mask && this.length > 0) {
|
41
|
+
input = $(this[0]);
|
42
|
+
var fn = input.data($.mask.dataName);
|
43
|
+
return fn ? fn() : void 0;
|
44
|
+
}
|
45
|
+
return settings = $.extend({
|
46
|
+
autoclear: $.mask.autoclear,
|
47
|
+
placeholder: $.mask.placeholder,
|
48
|
+
completed: null
|
49
|
+
}, settings), defs = $.mask.definitions, tests = [], partialPosition = len = mask.length,
|
50
|
+
firstNonMaskPos = null, $.each(mask.split(""), function(i, c) {
|
51
|
+
"?" == c ? (len--, partialPosition = i) : defs[c] ? (tests.push(new RegExp(defs[c])),
|
52
|
+
null === firstNonMaskPos && (firstNonMaskPos = tests.length - 1), partialPosition > i && (lastRequiredNonMaskPos = tests.length - 1)) : tests.push(null);
|
53
|
+
}), this.trigger("unmask").each(function() {
|
54
|
+
function tryFireCompleted() {
|
55
|
+
if (settings.completed) {
|
56
|
+
for (var i = firstNonMaskPos; lastRequiredNonMaskPos >= i; i++) if (tests[i] && buffer[i] === getPlaceholder(i)) return;
|
57
|
+
settings.completed.call(input);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
function getPlaceholder(i) {
|
61
|
+
return settings.placeholder.charAt(i < settings.placeholder.length ? i : 0);
|
62
|
+
}
|
63
|
+
function seekNext(pos) {
|
64
|
+
for (;++pos < len && !tests[pos]; ) ;
|
65
|
+
return pos;
|
66
|
+
}
|
67
|
+
function seekPrev(pos) {
|
68
|
+
for (;--pos >= 0 && !tests[pos]; ) ;
|
69
|
+
return pos;
|
70
|
+
}
|
71
|
+
function shiftL(begin, end) {
|
72
|
+
var i, j;
|
73
|
+
if (!(0 > begin)) {
|
74
|
+
for (i = begin, j = seekNext(end); len > i; i++) if (tests[i]) {
|
75
|
+
if (!(len > j && tests[i].test(buffer[j]))) break;
|
76
|
+
buffer[i] = buffer[j], buffer[j] = getPlaceholder(j), j = seekNext(j);
|
77
|
+
}
|
78
|
+
writeBuffer(), input.caret(Math.max(firstNonMaskPos, begin));
|
79
|
+
}
|
80
|
+
}
|
81
|
+
function shiftR(pos) {
|
82
|
+
var i, c, j, t;
|
83
|
+
for (i = pos, c = getPlaceholder(pos); len > i; i++) if (tests[i]) {
|
84
|
+
if (j = seekNext(i), t = buffer[i], buffer[i] = c, !(len > j && tests[j].test(t))) break;
|
85
|
+
c = t;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
function androidInputEvent() {
|
89
|
+
var curVal = input.val(), pos = input.caret();
|
90
|
+
if (curVal.length < oldVal.length) {
|
91
|
+
for (checkVal(!0); pos.begin > 0 && !tests[pos.begin - 1]; ) pos.begin--;
|
92
|
+
if (0 === pos.begin) for (;pos.begin < firstNonMaskPos && !tests[pos.begin]; ) pos.begin++;
|
93
|
+
input.caret(pos.begin, pos.begin);
|
94
|
+
} else {
|
95
|
+
for (checkVal(!0); pos.begin < len && !tests[pos.begin]; ) pos.begin++;
|
96
|
+
input.caret(pos.begin, pos.begin);
|
97
|
+
}
|
98
|
+
tryFireCompleted();
|
99
|
+
}
|
100
|
+
function blurEvent() {
|
101
|
+
checkVal(), input.val() != focusText && input.change();
|
102
|
+
}
|
103
|
+
function keydownEvent(e) {
|
104
|
+
if (!input.prop("readonly")) {
|
105
|
+
var pos, begin, end, k = e.which || e.keyCode;
|
106
|
+
oldVal = input.val(), 8 === k || 46 === k || iPhone && 127 === k ? (pos = input.caret(),
|
107
|
+
begin = pos.begin, end = pos.end, end - begin === 0 && (begin = 46 !== k ? seekPrev(begin) : end = seekNext(begin - 1),
|
108
|
+
end = 46 === k ? seekNext(end) : end), clearBuffer(begin, end), shiftL(begin, end - 1),
|
109
|
+
e.preventDefault()) : 13 === k ? blurEvent.call(this, e) : 27 === k && (input.val(focusText),
|
110
|
+
input.caret(0, checkVal()), e.preventDefault());
|
111
|
+
}
|
112
|
+
}
|
113
|
+
function keypressEvent(e) {
|
114
|
+
if (!input.prop("readonly")) {
|
115
|
+
var p, c, next, k = e.which || e.keyCode, pos = input.caret();
|
116
|
+
if (!(e.ctrlKey || e.altKey || e.metaKey || 32 > k) && k && 13 !== k) {
|
117
|
+
if (pos.end - pos.begin !== 0 && (clearBuffer(pos.begin, pos.end), shiftL(pos.begin, pos.end - 1)),
|
118
|
+
p = seekNext(pos.begin - 1), len > p && (c = String.fromCharCode(k), tests[p].test(c))) {
|
119
|
+
if (shiftR(p), buffer[p] = c, writeBuffer(), next = seekNext(p), android) {
|
120
|
+
var proxy = function() {
|
121
|
+
$.proxy($.fn.caret, input, next)();
|
122
|
+
};
|
123
|
+
setTimeout(proxy, 0);
|
124
|
+
} else input.caret(next);
|
125
|
+
pos.begin <= lastRequiredNonMaskPos && tryFireCompleted();
|
126
|
+
}
|
127
|
+
e.preventDefault();
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
function clearBuffer(start, end) {
|
132
|
+
var i;
|
133
|
+
for (i = start; end > i && len > i; i++) tests[i] && (buffer[i] = getPlaceholder(i));
|
134
|
+
}
|
135
|
+
function writeBuffer() {
|
136
|
+
input.val(buffer.join(""));
|
137
|
+
}
|
138
|
+
function checkVal(allow) {
|
139
|
+
var i, c, pos, test = input.val(), lastMatch = -1;
|
140
|
+
for (i = 0, pos = 0; len > i; i++) if (tests[i]) {
|
141
|
+
for (buffer[i] = getPlaceholder(i); pos++ < test.length; ) if (c = test.charAt(pos - 1),
|
142
|
+
tests[i].test(c)) {
|
143
|
+
buffer[i] = c, lastMatch = i;
|
144
|
+
break;
|
145
|
+
}
|
146
|
+
if (pos > test.length) {
|
147
|
+
clearBuffer(i + 1, len);
|
148
|
+
break;
|
149
|
+
}
|
150
|
+
} else buffer[i] === test.charAt(pos) && pos++, partialPosition > i && (lastMatch = i);
|
151
|
+
return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val() && input.val(""),
|
152
|
+
clearBuffer(0, len)) : writeBuffer() : (writeBuffer(), input.val(input.val().substring(0, lastMatch + 1))),
|
153
|
+
partialPosition ? i : firstNonMaskPos;
|
154
|
+
}
|
155
|
+
var input = $(this), buffer = $.map(mask.split(""), function(c, i) {
|
156
|
+
return "?" != c ? defs[c] ? getPlaceholder(i) : c : void 0;
|
157
|
+
}), defaultBuffer = buffer.join(""), focusText = input.val();
|
158
|
+
input.data($.mask.dataName, function() {
|
159
|
+
return $.map(buffer, function(c, i) {
|
160
|
+
return tests[i] && c != getPlaceholder(i) ? c : null;
|
161
|
+
}).join("");
|
162
|
+
}), input.one("unmask", function() {
|
163
|
+
input.off(".mask").removeData($.mask.dataName);
|
164
|
+
}).on("focus.mask", function() {
|
165
|
+
if (!input.prop("readonly")) {
|
166
|
+
clearTimeout(caretTimeoutId);
|
167
|
+
var pos;
|
168
|
+
focusText = input.val(), pos = checkVal(), caretTimeoutId = setTimeout(function() {
|
169
|
+
writeBuffer(), pos == mask.replace("?", "").length ? input.caret(0, pos) : input.caret(pos);
|
170
|
+
}, 10);
|
171
|
+
}
|
172
|
+
}).on("blur.mask", blurEvent).on("keydown.mask", keydownEvent).on("keypress.mask", keypressEvent).on("input.mask paste.mask", function() {
|
173
|
+
input.prop("readonly") || setTimeout(function() {
|
174
|
+
var pos = checkVal(!0);
|
175
|
+
input.caret(pos), tryFireCompleted();
|
176
|
+
}, 0);
|
177
|
+
}), chrome && android && input.off("input.mask").on("input.mask", androidInputEvent),
|
178
|
+
checkVal();
|
179
|
+
});
|
180
|
+
}
|
181
|
+
});
|
182
|
+
});
|
@@ -14,9 +14,11 @@ module Effective
|
|
14
14
|
|
15
15
|
def effective_select(method, options_tag = nil, options = {}, html_options = {})
|
16
16
|
options[:collection] = options_tag
|
17
|
-
options[:label_method] = :to_s if options[:label_method].nil?
|
18
|
-
options[:value_method] = :to_s if options[:value_method].nil?
|
19
17
|
Inputs::EffectiveSelect::Input.new(@object, @object_name, @template, method, options, html_options).to_html
|
20
18
|
end
|
19
|
+
|
20
|
+
def effective_tel(method, options_tag = nil, options = {}, html_options = {})
|
21
|
+
Inputs::EffectiveTel::Input.new(@object, @object_name, @template, method, options, html_options).to_html
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
@@ -10,6 +10,8 @@ module Effective
|
|
10
10
|
# Initialize 3 options Hashes: @opts, @html_opts, and @js_opts
|
11
11
|
@js_opts = opts.delete(:input_js).presence || {}
|
12
12
|
@html_opts = html_opts.presence || opts.delete(:input_html) || {}
|
13
|
+
@html_opts.delete(:placeholder) if @html_opts[:placeholder] == nil # SimpleForm oddity
|
14
|
+
|
13
15
|
@opts = opts.presence || {}
|
14
16
|
|
15
17
|
# Copy the following keys from options to html_options
|
@@ -60,6 +62,7 @@ module Effective
|
|
60
62
|
html_options().tap do |html_options|
|
61
63
|
html_options['data-input-js-options'] = (JSON.generate(js_options) rescue {})
|
62
64
|
html_options[:class] = html_options[:class].join(' ')
|
65
|
+
html_options[:placeholder] = (html_options[:placeholder].presence || options[:placeholder])
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
@@ -16,14 +16,19 @@ module Inputs
|
|
16
16
|
return text_field_tag(field_name, value, tag_options)
|
17
17
|
end
|
18
18
|
|
19
|
-
content_tag(:div, :
|
20
|
-
content_tag(:span, :
|
21
|
-
content_tag(:i, '', :
|
19
|
+
content_tag(:div, class: 'input-group') do
|
20
|
+
content_tag(:span, class: 'input-group-addon') do
|
21
|
+
content_tag(:i, '', class: 'glyphicon glyphicon-calendar').html_safe
|
22
22
|
end +
|
23
23
|
text_field_tag(field_name, value, tag_options)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def value
|
28
|
+
val = super
|
29
|
+
val.kind_of?(Time) ? val.to_date : val
|
30
|
+
end
|
31
|
+
|
27
32
|
def html_options
|
28
33
|
super.tap do |html_options|
|
29
34
|
if js_options[:format] == default_input_js[:format] # Unless someone changed from the default
|
@@ -16,9 +16,9 @@ module Inputs
|
|
16
16
|
return text_field_tag(field_name, value, tag_options)
|
17
17
|
end
|
18
18
|
|
19
|
-
content_tag(:div, :
|
20
|
-
content_tag(:span, :
|
21
|
-
content_tag(:i, '', :
|
19
|
+
content_tag(:div, class: 'input-group') do
|
20
|
+
content_tag(:span, class: 'input-group-addon') do
|
21
|
+
content_tag(:i, '', class: 'glyphicon glyphicon-calendar').html_safe
|
22
22
|
end +
|
23
23
|
text_field_tag(field_name, value, tag_options)
|
24
24
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Inputs
|
2
|
+
module EffectiveTel
|
3
|
+
class Input < Effective::FormInput
|
4
|
+
delegate :content_tag, :text_field_tag, :to => :@template
|
5
|
+
|
6
|
+
DEFAULT_TEL_MASK = '(999) 999-9999? x99999'
|
7
|
+
DEFAULT_CELL_MASK = '(999) 999-9999'
|
8
|
+
|
9
|
+
def default_options
|
10
|
+
{cellphone: false}
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_input_html
|
14
|
+
{class: 'effective_tel tel'}
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_input_js
|
18
|
+
{mask: DEFAULT_TEL_MASK, placeholder: '_'}
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_html
|
22
|
+
if options[:input_group] == false
|
23
|
+
return text_field_tag(field_name, value, tag_options)
|
24
|
+
end
|
25
|
+
|
26
|
+
content_tag(:div, class: 'input-group') do
|
27
|
+
content_tag(:span, class: 'input-group-addon') do
|
28
|
+
content_tag(:i, '', class: "glyphicon glyphicon-#{options[:cellphone] ? 'phone' : 'earphone'}").html_safe
|
29
|
+
end +
|
30
|
+
text_field_tag(field_name, value, tag_options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def js_options
|
35
|
+
super.tap do |js_options|
|
36
|
+
if options[:cellphone] == true && js_options[:mask] == DEFAULT_TEL_MASK
|
37
|
+
js_options[:mask] = DEFAULT_CELL_MASK
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# = simple_form_for @thing do |f|
|
2
|
+
# = f.input :phone, :as => :effective_tel
|
3
|
+
|
4
|
+
if defined?(SimpleForm)
|
5
|
+
|
6
|
+
class EffectiveTelInput < SimpleForm::Inputs::StringInput
|
7
|
+
def input(wrapper_options = nil)
|
8
|
+
Inputs::EffectiveTel::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
|
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.
|
4
|
+
version: 0.6.0
|
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: 2015-06-
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,6 +58,9 @@ files:
|
|
58
58
|
- app/assets/javascripts/effective_select/initialize.js.coffee
|
59
59
|
- app/assets/javascripts/effective_select/input.js
|
60
60
|
- app/assets/javascripts/effective_select/select2.js
|
61
|
+
- app/assets/javascripts/effective_tel/initialize.js.coffee
|
62
|
+
- app/assets/javascripts/effective_tel/input.js
|
63
|
+
- app/assets/javascripts/effective_tel/jquery.maskedInput.js
|
61
64
|
- app/assets/stylesheets/effective_date_picker/input.scss
|
62
65
|
- app/assets/stylesheets/effective_date_time_picker/bootstrap-datetimepicker.scss
|
63
66
|
- app/assets/stylesheets/effective_date_time_picker/input.scss
|
@@ -76,6 +79,8 @@ files:
|
|
76
79
|
- app/models/inputs/effective_select_input.rb
|
77
80
|
- app/models/inputs/effective_static_control/input.rb
|
78
81
|
- app/models/inputs/effective_static_control_input.rb
|
82
|
+
- app/models/inputs/effective_tel/input.rb
|
83
|
+
- app/models/inputs/effective_tel_input.rb
|
79
84
|
- app/views/effective/style_guide/_form_default.html.haml
|
80
85
|
- lib/effective_form_inputs.rb
|
81
86
|
- lib/effective_form_inputs/engine.rb
|