ActiveAdmin Autocomplete dropdown select not working - ruby-on-rails-3

I am using activeadmin 0.4.4 along with rails3-jquery-autocomplete 1.0.15.
I was able to add autocomplete to a field.The dropdown shows perfectly as required.
However I am not able to select a value from the dropdown. (If I manually write the value in the text field it works fine). I get this error in the browser console and I am unable to figure out on how to proceed with this:
Uncaught TypeError: undefined is not a function
t.railsAutocomplete.fn.extend.init.t.autocomplete.select -- active_adimn.js line 13982
Please suggest.

Just installing activeadmin_addons gem you can convert select controls into select2 controls. Use active admin's DSL as normal:
form do |f|
f.inputs 'Detalles' do
f.input :brand
# more inputs...
end
end
to get this:
If you want the normal select control, add default-select class like this:
form do |f|
f.inputs 'Detalles' do
f.input :brand, input_html: { class: 'default-select' }
# more inputs...
end
end
to get this:

Related

Simple form input as dropdown not select box

I have a input with a collection that should display as a drop down but instead it's displaying as a select box. How do i make it a drop down?
<%= f.input :fund, collection: funds, prompt: 'Select Fund', label: false, input_html: { multiple: true } %>
Add as: :select to your HTML and remove the multiple: true attribute. The select tag as a dropdown list does not support multiple selections without a JavaScript library like Select2.
<%= f.input :fund, as: :select, collection: funds, prompt: 'Select Fund', label: false %>
Here is an example of each type of select: http://jsfiddle.net/scarver2/s1nckfq5/
CITE: https://github.com/plataformatec/simple_form#usage
I answered a similar question here but you don't say what context (web framework) you're using.
You can use SimpleForm, Bootstrap and Bootstrap-Select. There is a Rails Gem for it. See my other answer for details.

readonly check box on simple form can still be updated

We use simple_form 2.0.2 in our rails 3.2 app. For some boolean fields, we want to make it readonly in certain situation and does not allow to update. Here is the code in our app:
<%= f.input :signed, :label => t('Signed'), :as => :boolean, :readonly => readonly?(#project, 'signed') %>
What we find out is that if :readonly => true, when mouse is over the field on simple form, there is a little red circle (with a slash in the circle) showing up. However the check box still could be changed and saved. Is there a way to make boolean check box on simple_form read only and can't be updated with :readonly? Thanks.
Not with :readonly, no.
The readonly HTML input attribute only prevents the user from changing the value of the field. It doesn't stop them from interacting with it, as clicking on it and toggling the checkmark shows. That only changes the state of the checkbox, whether it's on or off.
The specs on the readonly attribute say this:
readonly
This Boolean attribute indicates that the user cannot modify the value of the control.
If you don't want them changing the state at all, you may want to use disabled:
disabled
This Boolean attribute indicates that the form control is not available for interaction. In particular, the click event will not be dispatched on disabled controls. Also, a disabled control's value isn't submitted with the form.
But since the input is not sent along, the value will be missing. So consider pairing it with a hidden field that actually holds the value.
<%= f.input :signed_display, :label => t('Signed'), :as => :boolean, :disabled => true %>
<%= f.input :signed, :as => :hidden, input_html: {value: #project} %>

simple_form error messages do not go away

I'm using simple_form with twitter bootstrap on Rails.
Everything works great, except when showing live validations in a form-inline class. My code for the form is:
<%= simple_form_for #message,
url: mailing_list_path,
html: { class: "form-inline" },
method: :post,
validate: true do |f| %>
<%= f.input_field :email_address, label: false %>
<%= f.submit "Submit" %>
<% end %>
This shows the error message properly (e.g. "is invalid"), but if I click off the input and then back on again, it adds another message (e.g. it would say "is invalid is invalid"). For example, two sequential invalid entries and then a blank entry would give:
Is there any way to have simple_form remove the existing error message before adding a new one?
EDIT:
I solved this using some ghetto js, but would still like to know if the functionality I mentioned above is built in. The divs are still there, they're just hidden instead of all showing together. Would be great to have them actually removed by the form validation...
$('input.email-address-input').on 'keyup', () ->
$(this).parent('form').siblings('.help-inline').hide()

How to show base errors on active_admin gem

In the admin area, how do i go about and show the base errors (errors not specific to a field?). Ideally i would like to do this for all models.
Thanks
I just found an easy way to get them.. but you still have to override the form:
ActiveAdmin.register Blah do
form do |f|
f.semantic_errors :blah
f.inputs do
f.input :one
f.input :two
end
f.buttons
end
end
Update
You can simplify it like this too:
form do |f|
f.semantic_errors :blah
f.inputs
f.buttons
end
end
Well I hope I don't get flamed for this, but I dug into the ActiveAdmin Code and found where the default form options are.
Monkey Patch:
module ActiveAdmin::Views::Pages
class Form < Base
private
def default_form_config
ActiveAdmin::PagePresenter.new do |f|
f.semantic_errors
f.inputs
f.actions
end
end
end
end
That will make all the forms by default show errors that were added to base.

How do i remove the authenticity_token from rails forms

I have worked out how to disable the authenticity_token in the controller but rails still creates the field in the forms. How do i turn this off as the server i am posting the form to needs a very specific set of field names.
In rails after 3.2.x you can pass a parameter into the form generator as suggested in another answer:
form_for #invoice, :url => external_url, :authenticity_token => false do |f|
...
<% end %>
In any rails version you can disable globally in config/application.rb, as in another answer:
config.action_controller.allow_forgery_protection = false
In rails 3.0.x you can disable on a page load basis in the controller by overriding the following method. Unfortunately, there seems to be no way to do this at the form level.
protected
def protect_against_forgery?
if ...
# results in the meta tag being ommitted and no forms having authenticity token
return false
else
# default implementation based on global config
return allow_forgery_protection
end
end
To disable it across your application, you can add this line to your config/application.rb:
config.action_controller.allow_forgery_protection = false
For external urls you can turn this of per form as follows:
<%= form_for #invoice, :url => external_url, :authenticity_token => false do |f|
...
<% end %>
Source: http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for