Skip to content

Commit 9780a41

Browse files
committed
feat: add hidden field with default author
1 parent ff944a0 commit 9780a41

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

app/cells/plugins/core/author/input.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
= render_field_id
33
= render_label
44
= render_input
5+
= render_hidden_value

app/cells/plugins/core/author_cell.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def render_label
2020
def render_input
2121
@options[:form].text_field 'data[author_name]', value: value, placeholder: @options[:placeholder], class: 'mdl-textfield__input', required: required?
2222
end
23+
24+
def render_hidden_value
25+
@options[:form].hidden_field 'data[default_author_name]', value: current_user.fullname
26+
end
2327
end
2428
end
2529
end

app/models/author_field_type.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
class AuthorFieldType < FieldType
2-
include Devise::Controllers::Helpers
3-
1+
class XAuthorFieldType < FieldType
42
attr_accessor :author_name
53
jsonb_accessor :data, author_name: :string
64

75
validates :author_name, presence: true, if: :validate_presence?
86

97
def data=(data_hash)
10-
if data_hash.deep_symbolize_keys[:author_name].blank?
11-
@author_name = current_user.fullname
12-
else
13-
@author_name = data_hash.deep_symbolize_keys[:author_name]
14-
end
8+
@author_name = data_hash.deep_symbolize_keys[:author_name]
159
end
1610

1711
def field_item_as_indexed_json_for_field_type(field_item, options = {})

0 commit comments

Comments
 (0)