heartcombo / simple_form

Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
http://blog.plataformatec.com.br/tag/simple_form
MIT License
8.21k stars 1.31k forks source link

Encrypted attributes always default to textarea #1829

Closed ldlamarc closed 1 month ago

ldlamarc commented 7 months ago

Environment

Current behavior

When using simple form on an Active Record with encrypted fields the encrypted fields are all mapped to textarea input ignoring their database type (text or string).

Expected behavior

Use input[type=text] if the database column is a string.

Patch locally to fix it

module SimpleFormEncryptedAttributesExtension
  private

  def find_attribute_column(attribute_name)
    if @object.respond_to?(:encrypted_attributes) && @object.encrypted_attributes && @object.encrypted_attributes.include?(attribute_name)
      return @object.column_for_attribute(attribute_name)
    end

    super
  end
end

SimpleForm::FormBuilder.prepend(SimpleFormEncryptedAttributesExtension)