Add color input

Add an input for color picker

Browser support for color picker is still limited but I don't see a reason not to support it within simple_form
This commit is contained in:
Gustavo Bazan 2018-10-30 11:17:23 +00:00
parent f5758fcd82
commit 7595be661a
5 changed files with 27 additions and 1 deletions

View File

@ -4,6 +4,7 @@
* Guess input type more carefully. [@sringling](https://github.com/sringling)
* Allow custom error on forms without model. [@victorperez](https://github.com/victorperez)
* Do not support Ruby < 2.3 anymore. [@gssbzn](https://github.com/gssbzn)
* Add color inout type. [@gssbzn](https://github.com/gssbzn)
### Bug fix
* Improve disabled option to input_field. [@betelgeuse](https://github.com/betelgeuse)

View File

@ -10,6 +10,7 @@ module SimpleForm
autoload :CollectionInput
autoload :CollectionRadioButtonsInput
autoload :CollectionSelectInput
autoload :ColorInput
autoload :DateTimeInput
autoload :FileInput
autoload :GroupedCollectionSelectInput

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
module SimpleForm
module Inputs
class ColorInput < Base
def input(wrapper_options = nil)
input_html_options[:type] ||= "color" if html5?
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@builder.text_field(attribute_name, merged_input_options)
end
end
end
end

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'test_helper'
class ColorInputTest < ActionView::TestCase
test 'input generates a color field' do
with_input_for @user, :favorite_color, :color
assert_select 'input[type=color].color#user_favorite_color'
end
end

View File

@ -91,7 +91,7 @@ class User
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
:special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids,
:citext, :hstore, :json, :jsonb, :hourly
:citext, :hstore, :json, :jsonb, :hourly, :favorite_color
def self.build(extra_attributes = {})
attributes = {