Create PasswordInput.
This commit is contained in:
parent
4a46716f9a
commit
6dfdbae374
|
@ -6,7 +6,8 @@ module SimpleForm
|
|||
include SimpleForm::Inputs
|
||||
|
||||
map_type :text, :file, :to => SimpleForm::Inputs::MappingInput
|
||||
map_type :string, :password, :email, :search, :tel, :url, :to => SimpleForm::Inputs::StringInput
|
||||
map_type :string, :email, :search, :tel, :url, :to => SimpleForm::Inputs::StringInput
|
||||
map_type :password, :to => SimpleForm::Inputs::PasswordInput
|
||||
map_type :integer, :decimal, :float, :to => SimpleForm::Inputs::NumericInput
|
||||
map_type :select, :radio, :check_boxes, :to => SimpleForm::Inputs::CollectionInput
|
||||
map_type :date, :time, :datetime, :to => SimpleForm::Inputs::DateTimeInput
|
||||
|
|
|
@ -8,6 +8,7 @@ module SimpleForm
|
|||
autoload :HiddenInput, 'simple_form/inputs/hidden_input'
|
||||
autoload :MappingInput, 'simple_form/inputs/mapping_input'
|
||||
autoload :NumericInput, 'simple_form/inputs/numeric_input'
|
||||
autoload :PasswordInput, 'simple_form/inputs/password_input'
|
||||
autoload :PriorityInput, 'simple_form/inputs/priority_input'
|
||||
autoload :StringInput, 'simple_form/inputs/string_input'
|
||||
end
|
||||
|
|
|
@ -16,6 +16,11 @@ module SimpleForm
|
|||
include SimpleForm::Components::Wrapper
|
||||
include SimpleForm::Components::Maxlength
|
||||
|
||||
# Enables certain components support to the given input.
|
||||
def self.enable(*args)
|
||||
args.each { |m| class_eval "def has_#{m}?; true; end" }
|
||||
end
|
||||
|
||||
attr_reader :attribute_name, :column, :input_type, :reflection,
|
||||
:options, :input_html_options
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module SimpleForm
|
||||
module Inputs
|
||||
class PasswordInput < Base
|
||||
def input
|
||||
input_html_options[:size] ||= [limit, SimpleForm.default_input_size].compact.min
|
||||
@builder.password_field(attribute_name, input_html_options)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def has_maxlength?
|
||||
true
|
||||
end
|
||||
|
||||
def has_placeholder?
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,18 +1,11 @@
|
|||
module SimpleForm
|
||||
module Inputs
|
||||
class StringInput < Base
|
||||
extend MapType
|
||||
|
||||
map_type :string, :email, :search, :tel, :url, :to => :text_field
|
||||
map_type :password, :to => :password_field
|
||||
|
||||
def input
|
||||
input_html_options[:size] ||= [limit, SimpleForm.default_input_size].compact.min
|
||||
input_html_options[:pattern] ||= pattern_validator if validate_pattern?
|
||||
if password? || SimpleForm.html5
|
||||
input_html_options[:type] ||= input_type unless string?
|
||||
end
|
||||
@builder.send(input_method, attribute_name, input_html_options)
|
||||
input_html_options[:type] ||= input_type if SimpleForm.html5 && !string?
|
||||
@builder.text_field(attribute_name, input_html_options)
|
||||
end
|
||||
|
||||
def input_html_classes
|
||||
|
@ -33,10 +26,6 @@ module SimpleForm
|
|||
input_type == :string
|
||||
end
|
||||
|
||||
def password?
|
||||
input_type == :password
|
||||
end
|
||||
|
||||
def validate_pattern?
|
||||
return unless has_validators?
|
||||
|
||||
|
|
|
@ -340,25 +340,6 @@ class InputTest < ActionView::TestCase
|
|||
assert_select 'input[pattern="\w+"]'
|
||||
end
|
||||
|
||||
test 'input should infer pattern from attributes when it is present as a password' do
|
||||
with_input_for @other_validating_user, :country, :password
|
||||
assert_select 'input[pattern="\w+"]'
|
||||
end
|
||||
|
||||
test 'input should not add pattern from attributes when html5 are turned off' do
|
||||
swap SimpleForm, :html5 => false do
|
||||
with_input_for @other_validating_user, :country, :password
|
||||
assert_no_select 'input[pattern="\w+"]'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input should not add pattern from attributes when browser validations are turned off' do
|
||||
swap SimpleForm, :browser_validations => false do
|
||||
with_input_for @other_validating_user, :country, :password
|
||||
assert_no_select 'input[pattern="\w+"]'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input should have step value of any except for integer attribute' do
|
||||
with_input_for @validating_user, :age, :float
|
||||
assert_select 'input[step="any"]'
|
||||
|
|
Loading…
Reference in New Issue