heartcombo--simple_form/lib/simple_form/components/readonly.rb

23 lines
547 B
Ruby
Raw Normal View History

2011-12-05 01:41:54 +00:00
module SimpleForm
module Components
# Needs to be enabled in order to do automatic lookups.
module Readonly
def readonly
2011-12-05 09:44:02 +00:00
if readonly_attribute? && !has_readonly?
2011-12-05 01:41:54 +00:00
input_html_options[:readonly] ||= true
2011-12-05 09:44:02 +00:00
input_html_classes << :readonly
2011-12-05 01:41:54 +00:00
end
nil
end
private
def readonly_attribute?
object.class.respond_to?(:readonly_attributes) &&
object.persisted? &&
object.class.readonly_attributes.include?(attribute_name.to_s)
2011-12-05 01:41:54 +00:00
end
end
end
end