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
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 am using ActiveAdmin with rails 4 and it is working fine. When I add an item, I am taken to the index page listing the new item/items and the filters on the right side. Also, there are the email and logout links at the top right.
My issue is when I add an item with an image the filters, email and logout links disappear.
If I delete the item with the image they appear again. I can add /new to the url and it still takes me to the form but I am trying to figure out why adding a picture removes the links.
here is my form:
form(:html => { :multipart => true }) do |f|
f.inputs "Size" do
f.input :title
f.input :description
f.input :price
f.input :image, :as => :file
f.input :developer_days
f.input :designer_days
f.input :name
end
f.actions
end
I just can't figure out why this happens.
Is it at all possible to add a custom button along side the submit and cancel button that is generated with f.actions in this case?
The documents state:
form do |f|
f.semantic_errors # shows errors on :base
f.inputs # builds an input field for every attribute
f.actions # adds the 'Submit' and 'Cancel' buttons
link_to 'Preview', preview_my_admin_panel_posts_path(#post)
end
How could I add something here?
Update
I have got my custom button to show now with this:
inputs 'Submit' do
f.actions do
f.action :submit
f.action :cancel
f.action :reset
li do
link_to 'Preview', preview_my_admin_panel_posts_path()
end
end
Now I can't seem to grab the form object and pass through the params for post, title and comments.
Yea, it is possible.
define an action_item:
action_item only: %i(new edit) do
link_to 'Preview', preview_my_admin_panel_posts_path(#post)
end
Ok, I think you could do the following:
form do |f|
f.semantic_errors
f.inputs
f.actions do
f.submit, as: :button, label: 'Optional custom label'
f.cancel, as: :link # I think could converted to button as submit
link_to 'Preview', preview_my_admin_panel_posts_path(#post)
end
end
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