Skip to content

Commit f8fa9a0

Browse files
committed
[Closes browsermedia#682] Improved :name input
<%= f.input :name, as: :name %> Now renders consistently formatted name field. * Removed:default option for text fields (documented alternative) * Show large full column input if no label. * Labels are disabled by default. * Placeholder is 'Name' by default.
1 parent 6a130eb commit f8fa9a0

File tree

17 files changed

+82
-74
lines changed

17 files changed

+82
-74
lines changed

app/helpers/cms/form_tag_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def forecasting_a_new_section?(form_object)
1616
Cms::Section.with_path(form_object.object.class.path).first.nil?
1717
end
1818

19+
1920
def slug_source_if(boolean)
2021
if boolean
2122
{input_html: {class: 'slug-source'}}

app/inputs/cms_text_field_input.rb

Lines changed: 0 additions & 29 deletions
This file was deleted.

app/inputs/name_input.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# A text field that is used for the Name fields of content.
2+
#
3+
# @example <%= f.name as: :name %>
4+
#
5+
# Add the following behaviors above and beyond
6+
# 1. Will generate a slug if the class requires it. (Requires a as: :path field to work)
7+
# 2. If no label is specified, it shows a larger than normal input which spans the full row.
8+
# 3. Labels are turned off by default.
9+
class NameInput < SimpleForm::Inputs::TextInput
10+
11+
def initialize(*args)
12+
super(*args)
13+
options[:label] = false if options[:label].nil?
14+
options[:placeholder] = "Name" if options[:placeholder].nil?
15+
end
16+
17+
def input
18+
add_slug_source_for_content_that_needs_it
19+
20+
unless options[:label]
21+
input_html_options[:class] << 'input-block-level input-xxlarge'
22+
end
23+
24+
@builder.text_field(attribute_name, input_html_options).html_safe
25+
end
26+
27+
protected
28+
29+
def add_slug_source_for_content_that_needs_it
30+
if should_autogenerate_slug?
31+
input_html_options[:class] << 'slug-source'
32+
end
33+
end
34+
35+
def should_autogenerate_slug?
36+
content_requires_slug_field? && (object.new_record? || (object.name.blank? && object.slug.blank?))
37+
end
38+
39+
def content_requires_slug_field?
40+
object.class.requires_slug?
41+
end
42+
end

app/views/cms/forms/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% end %>
44

55
<h3>Form Settings</h3>
6-
<%= f.input :name, as: :cms_text_field %>
6+
<%= f.input :name, as: :name %>
77
<%= f.input :slug, as: :path %>
88
<%= f.input :description %>
99
<%= hidden_field_tag "field_ids", @block.field_ids %>

app/views/cms/pages/_main_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%= f.hidden_field :lock_version %>
66
<% end %>
77

8-
<%= f.input :name, label: false, placeholder: 'Page Name', input_html: {class: 'input-block-level input-xxlarge'} %>
8+
<%= f.input :name, placeholder: 'Page Name', as: :name %>
99
<%= f.input :path, placeholder: 'Page Path' %>
1010
<%= f.input :template_file_name, collection: Cms::PageTemplate.options, label: "Template", as: :select, include_blank: false %>
1111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%= f.input :name %>
22
<%= f.input :sender, hint: "Enter the email for the 'from' field on any emails sent out." %>
3-
<%= f.input :subject, as: :cms_text_field, default: "A link you might be interested in" %>
3+
<%= f.input :subject, input_html: { value: f.object.subject || "A link you might be interested in" } %>
44
<%= f.input :success_url, hint: "Leave blank to return the same page" %>
55
<%= f.input :template, as: :template_editor %>

app/views/portlets/list/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</div>
2020
<% end %>
2121
<% end %>
22-
<%= f.input :name, placeholder: 'Name', label: false, input_html: {class: 'input-block-level input-xxlarge'} %>
22+
<%= f.input :name, as: :name %>
2323
<%= f.input :content_type,
2424
collection: Cms::ContentType.available,
2525
label_method: :display_name,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<%= f.input :name %>
22
<%= f.input :limit, :size => 4 %>
3-
<%= f.input :sizes, :default => TagCloudPortlet.default_sizes, as: :cms_text_field %>
3+
<%= f.input :sizes, input_html: { value: f.object.sizes || TagCloudPortlet.default_sizes } %>
44
<%= f.input :template, as: :template_editor %>

doc/features/simple_form_refactor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ All of the existing simple_form input mappings are available. See http://simple-
3030
Here are some examples showing how to use the CMS specific inputs.
3131

3232
```
33-
<%= f.input :name, as: :cms_text_field, default: "Some Value" %>
33+
<%= f.input :name %>
3434
```
3535

36-
Generates the 'name' field, and a :path input if the content block is addressable. Can supply a default value that will be used when creating a new record.
36+
Generates the 'name' field as a text field.
3737

3838
```
3939
<%= f.input :expires_on, as: :date_picker %>

doc/release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v4.0.0.beta
22

33
* List Portlet [#678] - A convenient way to find content without custom coding.
4+
* NameInput [#682] - Improved :name input allows for consistent name fields look/feel. New content will be generated with it.
45

56
## [#678] List Portlet
67

0 commit comments

Comments
 (0)