Skip to content

Commit

Permalink
Merge pull request #1572 from tvdeyen/fix-resource-datepicker
Browse files Browse the repository at this point in the history
Use SimpleForm field for datepicker in resources form
  • Loading branch information
tvdeyen authored Apr 26, 2019
2 parents 7609440 + fb93799 commit 284c683
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
8 changes: 0 additions & 8 deletions app/views/alchemy/admin/resources/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
label_method: relation[:attr_method],
include_blank: Alchemy.t(:blank, scope: 'resources.relation_select'),
input_html: {class: 'alchemy_selectbox'} %>
<% elsif attribute[:type].to_s =~ /(date|time)/ %>
<div class="input <%= attribute[:type] %>">
<label class="control-label">
<%= f.object.class.human_attribute_name(attribute[:name]) %>
</label>
<%= alchemy_datepicker resource_instance_variable, attribute[:name],
type: attribute[:type] %>
</div>
<% else %>
<%= f.input attribute[:name], resource_attribute_field_options(attribute) %>
<% end %>
Expand Down
18 changes: 9 additions & 9 deletions lib/alchemy/resources_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ def render_attribute(resource, attribute, options = {})
# Returns a options hash for simple_form input fields.
def resource_attribute_field_options(attribute)
options = {hint: resource_handler.help_text_for(attribute)}
case attribute[:type].to_s
input_type = attribute[:type].to_s
case input_type
when 'boolean'
options
when 'date', 'datetime'
options.merge as: 'string',
when 'date', 'time', 'datetime'
date = resource_instance_variable.send(attribute[:name]) || Time.current
options.merge(
as: 'string',
input_html: {
type: attribute[:type].to_s,
value: l(resource_instance_variable.send(attribute[:name]) || Time.current,
format: "#{attribute[:type]}picker".to_sym
)
'data-datepicker-type' => input_type,
value: date ? date.iso8601 : nil
}
when 'time'
options.merge(as: 'time')
)
when 'text'
options.merge(as: 'text', input_html: {rows: 4})
else
Expand Down

0 comments on commit 284c683

Please sign in to comment.