-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
407 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.multi_value { | ||
.btn.remove { | ||
color: $brand-danger; | ||
} | ||
|
||
.btn.remove, .btn.add { | ||
text-decoration: underline; | ||
} | ||
|
||
.btn.add { | ||
padding-left: 0; | ||
} | ||
|
||
.field-wrapper { | ||
list-style-type:none; | ||
} | ||
|
||
.listing { | ||
margin-left: 0; | ||
max-width: 40em; | ||
padding-left: 0px; | ||
margin-bottom: 0; | ||
} | ||
|
||
.field-controls { | ||
margin-left: 2em; | ||
} | ||
|
||
.remove .glyphicon-remove, | ||
.add .glyphicon-plus { | ||
margin-right: 0.3rem | ||
} | ||
|
||
.message { | ||
background-size: 40px 40px; | ||
background-image: linear-gradient(135deg, rgba(255, 255, 255, .05) 25%, transparent 25%, | ||
transparent 50%, rgba(255, 255, 255, .05) 50%, rgba(255, 255, 255, .05) 75%, | ||
transparent 75%, transparent); | ||
box-shadow: inset 0 -1px 0 rgba(255,255,255,.4); | ||
width: 100%; | ||
border: 1px solid; | ||
color: #fff; | ||
padding: 10px; | ||
text-shadow: 0 1px 0 rgba(0,0,0,.5); | ||
animation: animate-bg 5s linear infinite; | ||
border-radius: $border-radius-base; | ||
} | ||
|
||
.has-error { | ||
background-color: #de4343; | ||
border-color: #c43d3d; | ||
} | ||
|
||
.has-warning{ | ||
background-color: #eaaf51; | ||
border-color: #d99a36; | ||
} | ||
|
||
.listing li:not(:last-child) { | ||
margin-bottom: 0.5rem; | ||
} | ||
|
||
.listing li:first-of-type { | ||
width: 83.3333333333%; | ||
|
||
input { | ||
border-radius: 4px; | ||
} | ||
|
||
.remove { | ||
display: none; | ||
} | ||
} | ||
} | ||
|
||
// The contributor listing needs some normalization | ||
#contributors .listing { | ||
max-width:20em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
class MultiValueInput < SimpleForm::Inputs::CollectionInput | ||
def input(_wrapper_options) | ||
@rendered_first_element = false | ||
input_html_classes.unshift("string") | ||
input_html_options[:name] ||= "#{object_name}[#{attribute_name}][]" | ||
|
||
outer_wrapper do | ||
buffer_each(collection) do |value, index| | ||
inner_wrapper do | ||
build_field(value, index) | ||
end | ||
end | ||
end | ||
end | ||
|
||
protected | ||
|
||
def buffer_each(collection) | ||
collection.each_with_object("".dup).with_index do |(value, buffer), index| | ||
buffer << yield(value, index) | ||
end | ||
end | ||
|
||
def outer_wrapper | ||
" <ul class=\"listing\">\n #{yield}\n </ul>\n" | ||
end | ||
|
||
def inner_wrapper | ||
<<-HTML | ||
<li class="field-wrapper"> | ||
#{yield} | ||
</li> | ||
HTML | ||
end | ||
|
||
private | ||
|
||
# Although the 'index' parameter is not used in this implementation it is useful in an | ||
# an overridden version of this method, especially when the field is a complex object and | ||
# the override defines nested fields. | ||
def build_field_options(value, _index) | ||
options = input_html_options.dup | ||
|
||
options[:value] = value | ||
if @rendered_first_element | ||
options[:id] = nil | ||
options[:required] = nil | ||
else | ||
options[:id] ||= input_dom_id | ||
end | ||
options[:class] ||= [] | ||
options[:class] += ["#{input_dom_id} form-control multi-text-field"] | ||
options[:'aria-labelledby'] = label_id | ||
@rendered_first_element = true | ||
|
||
options | ||
end | ||
|
||
def build_field(value, index) | ||
options = build_field_options(value, index) | ||
if options.delete(:type) == "textarea" | ||
@builder.text_area(attribute_name, options) | ||
else | ||
@builder.text_field(attribute_name, options) | ||
end | ||
end | ||
|
||
def label_id | ||
input_dom_id + "_label" | ||
end | ||
|
||
def input_dom_id | ||
input_html_options[:id] || "#{object_name}_#{attribute_name}" | ||
end | ||
|
||
def collection | ||
@collection ||= | ||
Array(object.send(attribute_name)).reject { |v| v.to_s.strip.blank? } + [""] | ||
end | ||
|
||
def multiple? | ||
true | ||
end | ||
end |
Oops, something went wrong.