I'm creating my forms using simple_form and it's all good, apart from when I want to just display some text rather than show an input box of some type. So I need to show a label and also the display text to go with it, e.g. Name : Chris, where "Name" is the label and "Chris" is the display text.
So Imagine I have a simple_form :
=simple_form_for @property do |f|
=f.display_field "Contact Name", "Chris"
=f.input :customer_reference
=f.input :premises_description
=f.input :po_number, :label=>"Purchase Order Number"
The "f.display_field" is a made up method, but it is how I imagine the method would look that I need. All it would do Is show a label and some text next to it. What is the easiest way to achieve this?
Cheers Chris
I use a custom input for this purpose:
class FakeInput < SimpleForm::Inputs::Base
# This method usually returns input's html like <input ... />
# but in this case it returns just a value of the attribute.
def input
@builder.object.send(attribute_name)
end
end
If you place it somewhere like in app/inputs/fake_input.rb you will be able to use it in your simple forms:
= simple_form_for @property do |f|
= f.input :contact_name, :as => :fake
The input's type is derived from the input's class name (without "Input", underscored). So for FakeInput it is :fake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With