mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
23 lines
543 B
Ruby
23 lines
543 B
Ruby
module SimpleForm
|
|
module Components
|
|
# Needs to be enabled in order to do automatic lookups.
|
|
module Readonly
|
|
def readonly
|
|
if readonly_attribute? && !has_readonly?
|
|
input_html_options[:readonly] ||= true
|
|
input_html_classes << :readonly
|
|
end
|
|
|
|
nil
|
|
end
|
|
|
|
private
|
|
|
|
def readonly_attribute?
|
|
object.class.respond_to?(:readonly_attributes) &&
|
|
object.persisted? &&
|
|
object.class.readonly_attributes.include?(attribute_name)
|
|
end
|
|
end
|
|
end
|
|
end
|