Skip to content

Instantly share code, notes, and snippets.

@owen2345
Last active November 13, 2016 14:18
Show Gist options
  • Save owen2345/b9cb0437b338ac712be59f6a7a7ebf70 to your computer and use it in GitHub Desktop.
Save owen2345/b9cb0437b338ac712be59f6a7a7ebf70 to your computer and use it in GitHub Desktop.
Camaleon CMS Create Own Custom Fields (Simple Country Select)
#/themes/e_shop/views/custom_field/_country_select.html.erb
<div class="group-input-fields-content">
<%= select_tag "#{field_name}[#{field.slug}][values][]", options_for_select(ISO3166::Country.all_names_with_codes), class: "form-control input-value #{"required" if field.options[:required].to_s.to_bool}" %>
</div>
// /themes/e_shop/config/config.json
{
...
...
"hooks": {
"extra_custom_fields": ["eshop_extra_custom_fields"]
}
}
#/themes/e_shop/config/Gemfile
gem 'country_select'
#/themes/e_shop/main_helper.rb
module Themes::EShop::MainHelper
def eshop_extra_custom_fields(args)
args[:fields][:my_country_select] = {
key: 'my_country_select',
label: 'Country Selector',
render: theme_view('custom_field/country_select.html.erb'),
options: {
required: true,
multiple: true,
}
}
end
end
@owen2345
Copy link
Author

Result:
screen shot 2016-08-16 at 11 58 24
country selector

@FlowerWrong
Copy link

FlowerWrong commented Nov 13, 2016

It is not work in https://github.com/owen2345/camaleon-cms/tree/master/spec/dummy, but work in standlone rails appliation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment