I have a Formtastic form and would like it to display a link in the hint if there's one.
f.input :link, hint: 'link here'
The solution I found to solve this was to use f.objectand then call the attribute link on it, like so:
form do |f|
f.inputs do
f.input :link, hint: link_to(f.object.link, f.object.link)
end
f.actions do
f.action :submit
end
end
Related
Can you please tell me if there is a way using simple_form with Rails, when you have "f.associations" present in a view, to disable the selected drop down menu in the form but still use the prefilled value of the field?
I have tried with option ":disabled => true" but it disables the whole text field and a I need a value to be present here. When I submit the form I receive an error that a value should be present.
I have tried with option ":as => :hidden", the input value does not appear, but when I submit the form I receive an error that a value should be present.
I have tried with option ":readonly => true", but drop down menu still appears. It appears grayed out but can still be selected.
Thank you,
Silviu
Use input hidden with same variable and value for f.assocation disabled, when submit form, the needing value will be sended at once time.
Sample code illustrate the case, note line f.association :company get the value company_id but not send, so the f.input :company_id will replace, and works!
Welcome to project railstrace !
<p>Simple Form content: </p>
<%= simple_form_for #user, url: save_path, :method => :post do |f| %>
<%= f.input :email %>
<%= f.association :company, disabled: true %>
<%= f.input :company_id, :as => :hidden, :input_html => {:value => #user.company_id} %>
<%= f.association :roles %>
<%= f.button :submit %>
<% end %>
i got the following issue:
I want to add a form on a custom page (no model) to design an email for mailjet. I already got a custom page and a form with an CKEditor input and an input for the subject. But the subject field isn't shown on the page.
This is my code:
ActiveAdmin.register_page "Mail", namespace: :lku do
def send_mail
end
content do
panel 'Write mail' do
semantic_form_for :mail, :url => "lku/send_mail", method: :post do |f|
f.inputs do
f.input :subject, :input_html => { :name => 'subject' }
end
f.inputs do
f.input :text, as: :ckeditor, :input_html => { :name => 'text' }
end
end
end
end
end
And this is the result:
When I add
f.actions
it looks like this
can someone help me please?
I was able to reproduce the problem without having ckeditor. Only the last element of form would display.
I don't know exactly what's going on, but it has something to do with how Arbre renders the content you generate inside the content block.
My solution is this
Transform the form content into .erb and move the form under views/lku/mail/_mailform.html.erb
<%= semantic_form_for :mail do |f| %>
<%= f.inputs do %>
<%= f.input :subject %>
<%= f.input :text %>
<% end %>
<%= f.actions %>
<% end %>
Include the form in the page
content do
panel 'Write mail' do
render partial: 'mailform'
end
end
See if you can still mount the editor by using regular Rails form helpers - https://github.com/galetahub/ckeditor#form-helpers
I've been using ActiveAdmin to create new posts for my news app, the problem is that even though I'm using the type "text' for my body property I don't know how to break lines when writing a new post.
That's my code:
ActiveAdmin.register Post do
permit_params :title, :body, :description, :remote_image_thumb_url, :remote_image_banner_url, :category_id
form do |f|
f.inputs "Post Details", :multipart => true do
f.collection_select :category_id, Category.all, :id, :name
f.input :title
f.input :body
f.input :description
f.input :remote_image_thumb_url
f.input :remote_image_banner_url
end
f.actions
end
end
I've been googling for a while but didn't fidn any solutions yet. Any ideas?
Rails saves the new lines when you hit the carriage return. However to render it is a different thing because it is naturally escaped.
You have a few options:
Use the default simple_format in rails.
Use a markdown renderer like Redcarpet to do that + alot more functionality.
I'd like to create a custom label for a simple form field. For some reason, the below code isn't creating that label. It's still using the default label. I must be missing something easy.
Simple Form 3.1
<%= simple_form_for "#" do |f| %>
<%= f.input :street, label: "Custom Label" %>
...
<% end %>
How can I create a custom label for my inputs in Simple Form?
You need to use a label helper along with your input helper:
<%= simple_form_for "#" do |f| %>
<%= f.label :street, 'Custom label' %>
<%= f.input :street, as: :string, label: false %>
<% end %>
You can also directly specify input types ie. f.text_field - More info : http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
You can now pass a label as argument. So the syntax as shown in the question (from 2015) now works:
<%= f.input :street, label: "Custom Label" %>
See the "Usage" section of the readme.
Iam working on active_admin form. my requirement is to add a button beside a input box to create new project
How to add a action item inside a form ?
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs "Details" do
f.input :task
f.input :project
f.input :members, :input_html => { :class => "chosen-input" }, :label => 'Assigned To'
f.actions
end
end
i want to add a new project button beside input field project
Though it is a very old question, stil i was also looking for the answer, This is how to do it:
just add it after f.input :project:
f.button "New Project", formaction: "new_entry", class: "some_class"
Then using member_action:
member_action :new_entry, method: :patch do
end
inputs 'Details' do
li do
label "Project"
span do
"here is your project input field"
end
span do
"here is your button"
end
end
end