Created
February 17, 2013 03:22
-
-
Save kulte/4969947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView | |
module Helpers | |
module FormHelper | |
def encrypted_text_field(object_name, method, options = {}) | |
InstanceTag.new(object_name, method, self, options.delete(:object)).to_encrypted_input_field_tag("text", options) | |
end | |
class InstanceTag | |
def to_encrypted_input_field_tag(field_type, options = {}) | |
options = options.stringify_keys | |
options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size") | |
options = DEFAULT_FIELD_OPTIONS.merge(options) | |
if field_type == "hidden" | |
options.delete("size") | |
end | |
options["type"] ||= field_type | |
options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file" | |
options["value"] &&= ERB::Util.html_escape(options["value"]) | |
add_default_name_and_id(options) | |
tag("input", options.merge({ "data-encrypted-name" => options.delete("name") })) | |
end | |
end | |
end | |
class FormBuilder | |
def encrypted_text_field(method, options = {}) | |
@template.encrypted_text_field(@object_name, method, objectify_options(options)) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment