Create Simple Custom Field

#/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

Created at: 08 Nov 09:36 | Updated at: 08 Nov 09:36