2010-02-06 16:21:26 -05:00
|
|
|
module SimpleForm
|
|
|
|
module Inputs
|
|
|
|
class StringInput < Base
|
2011-03-02 04:32:10 -05:00
|
|
|
extend MapType
|
|
|
|
|
|
|
|
map_type :string, :email, :search, :tel, :url, :to => :text_field
|
|
|
|
map_type :password, :to => :password_field
|
|
|
|
|
2010-02-06 16:21:26 -05:00
|
|
|
def input
|
2010-11-07 04:41:33 -05:00
|
|
|
input_html_options[:size] ||= [limit, SimpleForm.default_input_size].compact.min
|
2011-08-30 20:16:00 -04:00
|
|
|
input_html_options[:pattern] ||= pattern_validator if validate_pattern?
|
2011-05-16 05:42:58 -04:00
|
|
|
if password? || SimpleForm.html5
|
Add configuration option to explicitly turn off HTML5 extensions.
This includes the new field types such as email, number, search, url,
tel, and the new attributes such as required, autofocus, maxlength, min, max, step.
None of these are technically allowed in the HTML4 or XHTML1.0 doc types.
Test coverage and updated README.
Update config file generator with new HTML5 option.
2011-04-01 19:31:48 -04:00
|
|
|
input_html_options[:type] ||= input_type unless string?
|
|
|
|
end
|
2011-03-02 04:32:10 -05:00
|
|
|
@builder.send(input_method, attribute_name, input_html_options)
|
2010-02-06 16:21:26 -05:00
|
|
|
end
|
|
|
|
|
2010-06-01 17:37:53 -04:00
|
|
|
def input_html_classes
|
2010-11-21 10:50:36 -05:00
|
|
|
string? ? super : super.unshift("string")
|
2010-06-01 17:37:53 -04:00
|
|
|
end
|
|
|
|
|
2010-02-06 16:21:26 -05:00
|
|
|
protected
|
|
|
|
|
2011-08-30 19:51:53 -04:00
|
|
|
def has_maxlength?
|
|
|
|
true
|
2010-02-06 16:21:26 -05:00
|
|
|
end
|
2010-11-07 04:41:33 -05:00
|
|
|
|
|
|
|
def has_placeholder?
|
2011-04-07 20:41:12 -04:00
|
|
|
placeholder_present?
|
2010-11-07 04:41:33 -05:00
|
|
|
end
|
2010-11-21 10:50:36 -05:00
|
|
|
|
|
|
|
def string?
|
|
|
|
input_type == :string
|
|
|
|
end
|
Add configuration option to explicitly turn off HTML5 extensions.
This includes the new field types such as email, number, search, url,
tel, and the new attributes such as required, autofocus, maxlength, min, max, step.
None of these are technically allowed in the HTML4 or XHTML1.0 doc types.
Test coverage and updated README.
Update config file generator with new HTML5 option.
2011-04-01 19:31:48 -04:00
|
|
|
|
|
|
|
def password?
|
|
|
|
input_type == :password
|
|
|
|
end
|
2011-08-30 20:16:00 -04:00
|
|
|
|
|
|
|
def validate_pattern?
|
|
|
|
return unless has_validators?
|
|
|
|
|
|
|
|
SimpleForm.html5 && SimpleForm.browser_validations && find_pattern_validator.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def pattern_validator
|
|
|
|
find_pattern_validator.options[:with].source
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_pattern_validator
|
|
|
|
attribute_validators.find { |v| ActiveModel::Validations::FormatValidator === v }
|
|
|
|
end
|
2010-02-06 16:21:26 -05:00
|
|
|
end
|
|
|
|
end
|
2010-03-05 18:39:42 -05:00
|
|
|
end
|