2011-12-05 01:41:54 +00:00
|
|
|
module SimpleForm
|
|
|
|
module Components
|
|
|
|
# Needs to be enabled in order to do automatic lookups.
|
|
|
|
module Readonly
|
2014-03-11 22:53:29 +00:00
|
|
|
def readonly(wrapper_options = nil)
|
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? &&
|
2012-06-21 13:29:28 +00:00
|
|
|
object.class.readonly_attributes.include?(attribute_name.to_s)
|
2011-12-05 01:41:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|