mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
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:
parent
f5758fcd82
commit
7595be661a
5 changed files with 27 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -10,6 +10,7 @@ module SimpleForm
|
|||
autoload :CollectionInput
|
||||
autoload :CollectionRadioButtonsInput
|
||||
autoload :CollectionSelectInput
|
||||
autoload :ColorInput
|
||||
autoload :DateTimeInput
|
||||
autoload :FileInput
|
||||
autoload :GroupedCollectionSelectInput
|
||||
|
|
14
lib/simple_form/inputs/color_input.rb
Normal file
14
lib/simple_form/inputs/color_input.rb
Normal 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
|
10
test/inputs/color_input_test.rb
Normal file
10
test/inputs/color_input_test.rb
Normal 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
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue