formagic 0.3.4 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/app/assets/javascripts/formagic.coffee +2 -0
- data/app/assets/javascripts/formagic/form.coffee +9 -39
- data/app/assets/javascripts/formagic/group.coffee +1 -11
- data/app/assets/javascripts/formagic/inputs/array.coffee +8 -26
- data/app/assets/javascripts/formagic/inputs/checkbox.coffee +3 -20
- data/app/assets/javascripts/formagic/inputs/color.coffee +2 -16
- data/app/assets/javascripts/formagic/inputs/date.coffee +6 -24
- data/app/assets/javascripts/formagic/inputs/datetime.coffee +6 -27
- data/app/assets/javascripts/formagic/inputs/document.coffee +9 -25
- data/app/assets/javascripts/formagic/inputs/documents.coffee +11 -32
- data/app/assets/javascripts/formagic/inputs/documents_reorder.coffee +1 -12
- data/app/assets/javascripts/formagic/inputs/file.coffee +2 -22
- data/app/assets/javascripts/formagic/inputs/hash.coffee +1 -4
- data/app/assets/javascripts/formagic/inputs/hidden.coffee +2 -19
- data/app/assets/javascripts/formagic/inputs/html.coffee +2 -18
- data/app/assets/javascripts/formagic/inputs/image.coffee +3 -2
- data/app/assets/javascripts/formagic/inputs/list.coffee +2 -21
- data/app/assets/javascripts/formagic/inputs/list_reorder.coffee +1 -12
- data/app/assets/javascripts/formagic/inputs/list_typeahead.coffee +1 -13
- data/app/assets/javascripts/formagic/inputs/markdown.coffee +2 -18
- data/app/assets/javascripts/formagic/inputs/password.coffee +2 -14
- data/app/assets/javascripts/formagic/inputs/redactor.coffee +2 -18
- data/app/assets/javascripts/formagic/inputs/redactor_character.coffee +1 -13
- data/app/assets/javascripts/formagic/inputs/redactor_images.coffee +0 -13
- data/app/assets/javascripts/formagic/inputs/select.coffee +2 -21
- data/app/assets/javascripts/formagic/inputs/select2.coffee +0 -13
- data/app/assets/javascripts/formagic/inputs/select2_multiple.coffee +90 -0
- data/app/assets/javascripts/formagic/inputs/select2_single.coffee +57 -0
- data/app/assets/javascripts/formagic/inputs/string.coffee +13 -34
- data/app/assets/javascripts/formagic/inputs/text.coffee +2 -13
- data/app/assets/javascripts/formagic/inputs/url.coffee +3 -12
- data/app/assets/stylesheets/formagic.scss +2 -0
- data/app/assets/stylesheets/formagic/actions.scss +9 -0
- data/app/assets/stylesheets/formagic/form.scss +16 -24
- data/app/assets/stylesheets/formagic/nested-form.scss +3 -9
- data/app/assets/stylesheets/formagic/select.scss +24 -5
- data/app/assets/stylesheets/formagic/url.scss +5 -0
- data/lib/formagic/version.rb +1 -1
- metadata +6 -2
@@ -1,32 +1,20 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT PASSWORD
|
11
6
|
# -----------------------------------------------------------------------------
|
12
7
|
class @InputPassword extends InputString
|
13
|
-
|
14
|
-
# PRIVATE ===============================================
|
8
|
+
# PRIVATE ===================================================================
|
15
9
|
|
16
10
|
_add_input: ->
|
17
11
|
@$input =$ "<input type='password' name='#{ @name }' value='#{ @value }' />"
|
18
12
|
@$input.on 'keyup', (e) => @$input.trigger('change')
|
19
13
|
@$el.append @$input
|
20
14
|
|
21
|
-
|
22
|
-
# PUBLIC ================================================
|
15
|
+
# PUBLIC ====================================================================
|
23
16
|
|
24
17
|
updateValue: (@value) ->
|
25
18
|
@$input.val(@value)
|
26
19
|
|
27
|
-
|
28
20
|
chr.formInputs['password'] = InputPassword
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
@@ -1,32 +1,23 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT REDACTOR
|
11
6
|
# -----------------------------------------------------------------------------
|
12
|
-
#
|
13
7
|
# Dependencies:
|
14
8
|
#= require vendor/redactor.table
|
15
9
|
#= require vendor/redactor.fixedtoolbar
|
16
10
|
#= require ./redactor_character
|
17
11
|
# -----------------------------------------------------------------------------
|
18
|
-
|
19
12
|
class @InputRedactor extends InputString
|
20
|
-
|
21
|
-
# PRIVATE ===============================================
|
13
|
+
# PRIVATE ===================================================================
|
22
14
|
|
23
15
|
_add_input: ->
|
24
16
|
@$el.css('opacity', 0)
|
25
17
|
@$input =$ "<textarea class='redactor' name='#{ @name }' rows=1>#{ @_safe_value() }</textarea>"
|
26
18
|
@$el.append @$input
|
27
19
|
|
28
|
-
|
29
|
-
# PUBLIC ================================================
|
20
|
+
# PUBLIC ====================================================================
|
30
21
|
|
31
22
|
initialize: ->
|
32
23
|
@config.beforeInitialize?(this)
|
@@ -37,17 +28,10 @@ class @InputRedactor extends InputString
|
|
37
28
|
|
38
29
|
@config.onInitialize?(this)
|
39
30
|
|
40
|
-
|
41
31
|
updateValue: (@value) ->
|
42
32
|
@_trigger_change = false
|
43
33
|
@$input.redactor('code.set', @value)
|
44
34
|
|
45
|
-
|
46
35
|
include(InputRedactor, redactorCharacter)
|
47
36
|
|
48
|
-
|
49
37
|
chr.formInputs['redactor'] = InputRedactor
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
@@ -1,11 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# REDACTOR CUSTOM VERSION
|
11
6
|
#= require ./redactor_images
|
@@ -17,8 +12,7 @@ console.log ':: [redactor-character] change $.fx.speeds.fast from 200 to 10 ::'
|
|
17
12
|
$.fx.speeds.fast = 10
|
18
13
|
|
19
14
|
@redactorCharacter =
|
20
|
-
|
21
|
-
# PRIVATE ===============================================
|
15
|
+
# PRIVATE ===================================================================
|
22
16
|
|
23
17
|
# TODO: fixed toolbar disabled on mobile
|
24
18
|
_redactor_options: ->
|
@@ -41,7 +35,6 @@ $.fx.speeds.fast = 10
|
|
41
35
|
|
42
36
|
return config
|
43
37
|
|
44
|
-
|
45
38
|
_get_default_config: () ->
|
46
39
|
focus: false
|
47
40
|
imageFloatMargin: '20px'
|
@@ -70,8 +63,3 @@ $.fx.speeds.fast = 10
|
|
70
63
|
|
71
64
|
initCallback: ->
|
72
65
|
new RedactorImages(this)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
@@ -1,15 +1,9 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# REDACTOR IMAGES
|
11
6
|
# -----------------------------------------------------------------------------
|
12
|
-
|
13
7
|
class @RedactorImages
|
14
8
|
constructor: (@redactor) ->
|
15
9
|
|
@@ -41,7 +35,6 @@ class @RedactorImages
|
|
41
35
|
<label class="redactor-image-link-option"><input type="checkbox" id="redactor-image-link-blank"> Open link in new tab</label>
|
42
36
|
</section>"""
|
43
37
|
|
44
|
-
|
45
38
|
update: ($image) ->
|
46
39
|
@redactor.image.hideResize()
|
47
40
|
@redactor.buffer.set()
|
@@ -85,7 +78,6 @@ class @RedactorImages
|
|
85
78
|
@redactor.observe.images()
|
86
79
|
@redactor.code.sync()
|
87
80
|
|
88
|
-
|
89
81
|
_show_edit: ($image) ->
|
90
82
|
$link = $image.closest('a')
|
91
83
|
|
@@ -126,7 +118,6 @@ class @RedactorImages
|
|
126
118
|
|
127
119
|
@redactor.modal.show()
|
128
120
|
|
129
|
-
|
130
121
|
# for some reason when image is a link, tooltip is shown with the image edit dialog,
|
131
122
|
# add e.stopPropagation() to skip tooltip callback
|
132
123
|
_load_editable_controls: ($image) ->
|
@@ -160,7 +151,3 @@ class @RedactorImages
|
|
160
151
|
@redactor.image.editter.css('margin-left', '-' + editerWidth/2 + 'px')
|
161
152
|
|
162
153
|
return @redactor.image.loadResizableControls($image, imageBox)
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
@@ -1,30 +1,21 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT SELECT
|
11
6
|
# -----------------------------------------------------------------------------
|
12
|
-
|
13
7
|
class @InputSelect extends InputString
|
14
|
-
|
15
|
-
# PRIVATE ===============================================
|
8
|
+
# PRIVATE ===================================================================
|
16
9
|
|
17
10
|
_create_el: ->
|
18
11
|
@$el =$ "<div class='form-input input-#{ @config.type } input-#{ @config.klassName }'>"
|
19
12
|
|
20
|
-
|
21
13
|
_add_input: ->
|
22
14
|
@$input =$ """<select name='#{ @name }'></select>"""
|
23
15
|
@$el.append @$input
|
24
16
|
|
25
17
|
@_add_options()
|
26
18
|
|
27
|
-
|
28
19
|
_add_options: ->
|
29
20
|
if @config.optionsHashFieldName
|
30
21
|
@value = String(@value)
|
@@ -42,33 +33,28 @@ class @InputSelect extends InputString
|
|
42
33
|
else if @config.optionsHash
|
43
34
|
@_add_hash_options()
|
44
35
|
|
45
|
-
|
46
36
|
_add_collection_options: ->
|
47
37
|
for o in @config.collection.data
|
48
38
|
title = o[@config.collection.titleField]
|
49
39
|
value = o[@config.collection.valueField]
|
50
40
|
@_add_option(title, value)
|
51
41
|
|
52
|
-
|
53
42
|
_add_list_options: ->
|
54
43
|
data = @config.optionsList
|
55
44
|
for o in data
|
56
45
|
@_add_option(o, o)
|
57
46
|
|
58
|
-
|
59
47
|
_add_hash_options: ->
|
60
48
|
data = @config.optionsHash
|
61
49
|
for value, title of data
|
62
50
|
@_add_option(title, value)
|
63
51
|
|
64
|
-
|
65
52
|
_add_option: (title, value) ->
|
66
53
|
selected = if @value == value then 'selected' else ''
|
67
54
|
$option =$ """<option value='#{ value }' #{ selected }>#{ title }</option>"""
|
68
55
|
@$input.append $option
|
69
56
|
|
70
|
-
|
71
|
-
# PUBLIC ================================================
|
57
|
+
# PUBLIC ====================================================================
|
72
58
|
|
73
59
|
updateValue: (@value, @object) ->
|
74
60
|
@$input.html('')
|
@@ -76,9 +62,4 @@ class @InputSelect extends InputString
|
|
76
62
|
|
77
63
|
@$input.val(@value).prop('selected', true)
|
78
64
|
|
79
|
-
|
80
65
|
chr.formInputs['select'] = InputSelect
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
@@ -1,20 +1,12 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT SELECT 2
|
11
6
|
# -----------------------------------------------------------------------------
|
12
|
-
#
|
13
7
|
# Dependencies:
|
14
8
|
#= require vendor/select2
|
15
|
-
#
|
16
9
|
# -----------------------------------------------------------------------------
|
17
|
-
|
18
10
|
class @InputSelect2 extends InputSelect
|
19
11
|
initialize: ->
|
20
12
|
@config.beforeInitialize?(this)
|
@@ -25,9 +17,4 @@ class @InputSelect2 extends InputSelect
|
|
25
17
|
|
26
18
|
@config.onInitialize?(this)
|
27
19
|
|
28
|
-
|
29
20
|
chr.formInputs['select2'] = InputSelect2
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
|
+
# Slate Studio (http://www.slatestudio.com)
|
4
|
+
# -----------------------------------------------------------------------------
|
5
|
+
# SELECT MULTIPLE
|
6
|
+
# -----------------------------------------------------------------------------
|
7
|
+
# Dependencies:
|
8
|
+
#= require ./select2
|
9
|
+
# -----------------------------------------------------------------------------
|
10
|
+
class @InputSelect2Multiple extends InputSelect2
|
11
|
+
initialize: ->
|
12
|
+
@config.beforeInitialize?(this)
|
13
|
+
|
14
|
+
target = @config.target
|
15
|
+
titleFieldName = @config.titleField
|
16
|
+
|
17
|
+
# Remove name from the select input so it's value is not send to the server
|
18
|
+
@$input.attr('name', '').attr('multiple', true)
|
19
|
+
|
20
|
+
# Attach hidden input to store value
|
21
|
+
@$hiddenInput =$ "<input type='hidden' name='[__LIST__#{ target }]' />"
|
22
|
+
@$el.append @$hiddenInput
|
23
|
+
|
24
|
+
# Add handler that updates hidden value on select change (updated by select2)
|
25
|
+
@$input.on 'change', (e) =>
|
26
|
+
@_update_hidden_input_value()
|
27
|
+
|
28
|
+
# These methods run while initialization only
|
29
|
+
@_initialize_selected_values()
|
30
|
+
@_update_hidden_input_value()
|
31
|
+
|
32
|
+
options =
|
33
|
+
placeholder: @config.placeholder
|
34
|
+
multiple: true
|
35
|
+
width: '100%'
|
36
|
+
ajax:
|
37
|
+
url: @config.url
|
38
|
+
dataType: 'json'
|
39
|
+
delay: 250
|
40
|
+
cache: true
|
41
|
+
minimumInputLength: 2
|
42
|
+
data: (params) -> { search: params.term, page: 1, perPage: 20 }
|
43
|
+
processResults: (data, page) ->
|
44
|
+
{ results: $.map data, (i) -> { id: i._id, text: i[titleFieldName] } }
|
45
|
+
|
46
|
+
# https://select2.github.io/options.html
|
47
|
+
$.extend(options, @config.pluginOptions || {})
|
48
|
+
@$input.select2(options)
|
49
|
+
|
50
|
+
@config.onInitialize?(this)
|
51
|
+
|
52
|
+
# PRIVATE =====================================================================
|
53
|
+
|
54
|
+
_selected_ids: ->
|
55
|
+
$.map @$input.children(':selected'), (option) ->
|
56
|
+
$(option).attr('value')
|
57
|
+
|
58
|
+
_selected_ids_and_names: ->
|
59
|
+
$.map input.$input.children(':selected'), (option) ->
|
60
|
+
{ _id: $(option).attr('value'), name: $(option).text() }
|
61
|
+
|
62
|
+
# Add initial values to be shown by select2
|
63
|
+
_initialize_selected_values: ->
|
64
|
+
titleFieldName = @config.titleField
|
65
|
+
for o in @value
|
66
|
+
@$input.append """
|
67
|
+
<option value='#{ o._id }' selected>
|
68
|
+
#{ o[titleFieldName] }
|
69
|
+
</option>"""
|
70
|
+
|
71
|
+
# Pass value to hidden input in list format (split ids with ,)
|
72
|
+
_update_hidden_input_value: ->
|
73
|
+
selectedValues = @_selected_ids()
|
74
|
+
val = selectedValues.join('|||')
|
75
|
+
@$hiddenInput.val(val)
|
76
|
+
|
77
|
+
# PUBLIC ======================================================================
|
78
|
+
|
79
|
+
# Override default updateValue method
|
80
|
+
updateValue: (@value) ->
|
81
|
+
@$input.html('')
|
82
|
+
@_initialize_selected_values()
|
83
|
+
@_update_hidden_input_value()
|
84
|
+
|
85
|
+
# Override hash method to cache values properly
|
86
|
+
hash: (hash={}) ->
|
87
|
+
hash[@config.klassName] = @_selected_ids_and_names()
|
88
|
+
return hash
|
89
|
+
|
90
|
+
chr.formInputs['selectMultiple'] = InputSelect2Multiple
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
|
+
# Slate Studio (http://www.slatestudio.com)
|
4
|
+
# -----------------------------------------------------------------------------
|
5
|
+
# SELECT SINGLE
|
6
|
+
# -----------------------------------------------------------------------------
|
7
|
+
# Dependencies:
|
8
|
+
#= require ./select2
|
9
|
+
# -----------------------------------------------------------------------------
|
10
|
+
# Configuration example:
|
11
|
+
#
|
12
|
+
# category_id:
|
13
|
+
# type: 'selectSingle'
|
14
|
+
# label: 'Category'
|
15
|
+
# titleField: 'title'
|
16
|
+
# url: "/admin/categories.json"
|
17
|
+
# relatedTitleField: 'category_title'
|
18
|
+
# -----------------------------------------------------------------------------
|
19
|
+
class @InputSelect2Multiple extends InputSelect2
|
20
|
+
initialize: ->
|
21
|
+
@config.beforeInitialize?(this)
|
22
|
+
|
23
|
+
titleFieldName = @config.titleField
|
24
|
+
@_initialize_options_hash(titleFieldName)
|
25
|
+
|
26
|
+
options =
|
27
|
+
placeholder: @config.placeholder
|
28
|
+
width: "100%"
|
29
|
+
ajax:
|
30
|
+
url: @config.url
|
31
|
+
dataType: 'json'
|
32
|
+
delay: 250
|
33
|
+
cache: true
|
34
|
+
minimumInputLength: 2
|
35
|
+
data: (params) -> { search: params.term, page: 1 }
|
36
|
+
processResults: (data, page) ->
|
37
|
+
{ results: $.map data, (i) -> { id: i._id, text: i[titleFieldName] } }
|
38
|
+
|
39
|
+
# https://select2.github.io/options.html
|
40
|
+
$.extend(options, @config.pluginOptions || {})
|
41
|
+
@$input.select2(options)
|
42
|
+
|
43
|
+
@config.onInitialize?(this)
|
44
|
+
|
45
|
+
# PRIVATE ===================================================================
|
46
|
+
|
47
|
+
_initialize_options_hash: ->
|
48
|
+
@config.optionsHash = {}
|
49
|
+
if @object
|
50
|
+
relatedObjectId = @object[@config.fieldName]
|
51
|
+
relatedObjectTitle = @object[@config.relatedTitleField]
|
52
|
+
if ! relatedObjectTitle
|
53
|
+
relatedObjectTitle = 'None'
|
54
|
+
@config.optionsHash[relatedObjectId] = relatedObjectTitle
|
55
|
+
@_add_options()
|
56
|
+
|
57
|
+
chr.formInputs['selectSingle'] = InputSelect2Multiple
|
@@ -1,11 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT STRING
|
11
6
|
# -----------------------------------------------------------------------------
|
@@ -21,7 +16,6 @@
|
|
21
16
|
#
|
22
17
|
# Dependencies:
|
23
18
|
#= require vendor/jquery.typeahead
|
24
|
-
#
|
25
19
|
# -----------------------------------------------------------------------------
|
26
20
|
class @InputString
|
27
21
|
constructor: (@name, @value, @config, @object) ->
|
@@ -35,8 +29,7 @@ class @InputString
|
|
35
29
|
|
36
30
|
return this
|
37
31
|
|
38
|
-
|
39
|
-
# PRIVATE ===============================================
|
32
|
+
# PRIVATE ===================================================================
|
40
33
|
|
41
34
|
_safe_value: ->
|
42
35
|
if typeof(@value) == 'object'
|
@@ -44,26 +37,28 @@ class @InputString
|
|
44
37
|
else
|
45
38
|
return _escapeHtml(@value)
|
46
39
|
|
47
|
-
|
48
40
|
_create_el: ->
|
49
41
|
@$el =$ "<label for='#{ @name }' class='#{ @config.klass } input-#{ @config.type } input-#{ @config.klassName }'>"
|
50
42
|
|
51
|
-
|
52
43
|
_add_label: ->
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
44
|
+
@$label =$ "<span class='label'>"
|
45
|
+
@$labelTitle =$ "<span class='label-title'>#{ @config.label }</span>"
|
46
|
+
@$errorMessage =$ "<span class='error-message'></span>"
|
47
|
+
@$label.append(@$labelTitle)
|
48
|
+
@$label.append(@$errorMessage)
|
49
|
+
@$el.append(@$label)
|
58
50
|
|
51
|
+
if @config.label == false
|
52
|
+
@$labelTitle.hide()
|
59
53
|
|
60
54
|
_add_input: ->
|
61
|
-
@$input =$ "
|
55
|
+
@$input =$ """
|
56
|
+
<input type='text' id='#{ @name }' name='#{ @name }' value='#{ @_safe_value() }' />
|
57
|
+
"""
|
62
58
|
# trigger change event on keyup so value is cached while typing
|
63
59
|
@$input.on 'keyup', (e) => @$input.trigger('change')
|
64
60
|
@$el.append @$input
|
65
61
|
|
66
|
-
|
67
62
|
if @config.options and $.isArray(@config.options)
|
68
63
|
data = new Bloodhound
|
69
64
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value')
|
@@ -83,25 +78,21 @@ class @InputString
|
|
83
78
|
source: data.ttAdapter()
|
84
79
|
})
|
85
80
|
|
86
|
-
|
87
81
|
_add_placeholder: ->
|
88
82
|
@$input.attr 'placeholder', @config.type
|
89
83
|
|
90
84
|
if @config.placeholder
|
91
85
|
@$input.attr 'placeholder', @config.placeholder
|
92
86
|
|
93
|
-
|
94
87
|
_add_disabled: ->
|
95
88
|
if @config.disabled
|
96
89
|
@$input.prop('disabled', true)
|
97
90
|
@$el.addClass('input-disabled')
|
98
91
|
|
99
|
-
|
100
92
|
_add_required: ->
|
101
93
|
if @config.required
|
102
94
|
@$el.addClass('input-required')
|
103
95
|
|
104
|
-
|
105
96
|
_add_limit: ->
|
106
97
|
if @config.limit
|
107
98
|
@$charCounter =$ "<span class='input-character-counter'></span>"
|
@@ -110,7 +101,6 @@ class @InputString
|
|
110
101
|
@_update_character_counter()
|
111
102
|
@_update_character_counter()
|
112
103
|
|
113
|
-
|
114
104
|
_update_character_counter: ->
|
115
105
|
characters = @$input.val().length
|
116
106
|
left = @config.limit - characters
|
@@ -121,40 +111,29 @@ class @InputString
|
|
121
111
|
else
|
122
112
|
@$charCounter.html("(#{ left })")
|
123
113
|
|
124
|
-
|
125
114
|
if characters > @config.limit
|
126
115
|
@$charCounter.addClass('exceeds')
|
127
116
|
else
|
128
117
|
@$charCounter.removeClass('exceeds')
|
129
118
|
|
130
|
-
|
131
|
-
# PUBLIC ================================================
|
119
|
+
# PUBLIC ====================================================================
|
132
120
|
|
133
121
|
initialize: ->
|
134
122
|
@config.onInitialize?(this)
|
135
123
|
|
136
|
-
|
137
124
|
hash: (hash={}) ->
|
138
125
|
hash[@config.klassName] = @$input.val()
|
139
126
|
return hash
|
140
127
|
|
141
|
-
|
142
128
|
updateValue: (@value) ->
|
143
129
|
@$input.val(@value)
|
144
130
|
|
145
|
-
|
146
131
|
showErrorMessage: (message) ->
|
147
132
|
@$el.addClass('error')
|
148
133
|
@$errorMessage.html(message)
|
149
134
|
|
150
|
-
|
151
135
|
hideErrorMessage: ->
|
152
136
|
@$el.removeClass('error')
|
153
137
|
@$errorMessage.html('')
|
154
138
|
|
155
|
-
|
156
139
|
chr.formInputs['string'] = InputString
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|