I'm working with rails' activeadmin and creating a custom form like so:
<%= semantic_form_for [:admin, Client.find(#wedding_cake.client_id), #wedding_cake] do |f| %>
than I want to add an input for a date like so:
<%= f.input :date, as: :datepicker %>
However, I'm getting "Unable to find input class for datepicker" from rails.
I've tried including jquery date picker in my gem file, but that didn't change anything. What am I doing wrong?
I ran into this exact issue and what worked for me was: https://github.com/activeadmin/activeadmin/wiki/Combine-datetime-picker-with-activeadmin#or-do-it-manually
Specifically:
In active_admin, change the column use
:as => datepicker TO :as => :string, :input_html => {:class => "hasDatetimePicker"}
However, I had to prepend the datepicker class, and in my case, change hasDatetimePicker to hasDatePicker
:as => :string, :input_html => {:class => 'datepicker hasDatePicker'}
h/t to Eugen's comment for pointing me in the right direction
Try the DateNTimePickerActiveAdmin Rubygem. It works really well and is customisable according to your project.
You can find the documentation here: https://github.com/NikhithaGraceJosh/date_n_time_picker_activeadmin
From the docs:
Gemfile
gem 'date_n_time_picker_activeadmin'
Code Sample (In your form)
f.input :column_name, as: :datetimepicker
CSS
In active_admin.scss, add the line,
#import date_n_time_picker_activeadmin
JS
In active_admin.js, add the line,
//= require date_n_time_picker_activeadmin
Hope it's useful!
Related
I am trying to use the autosize-rails gem to create text boxes that automatically get bigger when filled. I installed the gem and bundled it.
gem 'autosize-rails
I then added this to my js.coffeescript file:
$(document).ready ->
$("textarea").autosize()
and finally my form looks like this:
<%= f.input :title, as: :text, input_html: { :class => "textarea" }%>
The forms still use the default scroll bar.
I have no experience with this gem, but it looks like you need to change $("textarea") to $(".textarea") in your coffeescript file.
I have a Rails project using simple_form and I can't seem to get the date picker to work (using the Bootstrap Datepicker gem https://github.com/Nerian/bootstrap-datepicker-rails.
I have tried what's been proposed in the following stack overflow posts:
How do i write a cleaner date picker input for SimpleForm
Add datepicker with rails 3.2.11, simple_form and bootstrap
Changes in the form are not saved to database
But, so far none of them have worked.
Here is my code:
In my View I have this:
<%= f.input :start_date, :input_html => {data: {behaviour: "datepicker"}}, :as => :string %>
I have added the following to Application.js
//= require bootstrap-datepicker
$(function() {
$('input.datepicker').datepicker();
});
I have added the following to Application.css
*= require bootstrap-datepicker
I've even tried putting the js code directly on the page and it still doesn't work.
Any ideas? I'm stumped.
Thanks
Your function assigning the datepicker behavior searches for inputs with class 'datepicker'. Your inputs must have this class.
Use the following:
<%= f.input :start_date, :input_html => {class: 'datepicker', data: {behaviour: "datepicker"}}, :as => :string %>
I'm using formtastic and I've got a field country.. I'm getting this error when I attempt to display the screen.
To use the :country input, please install a country_select plugin,
like this one: https://github.com/jamesds/country-select
Now. I don't want to use any plugin.. It's free text, and I want to keep it that way.
Anyone know how to remove this requirement? Should be easy as... but I'm buggered if I can see how.
= semantic_form_for #store, {:html => { :class => "form-horizontal" }} do |f|
= f.input :default_country
Add
, :as => :string
to the end of the line that's causing the error
= semantic_form_for #store, {:html => { :class => "form-horizontal" }} do |f|
= f.input :default_country, :as => :string
In Rails 4, formtastic with country select input field:
Add 'country-select' to your Gemfile:
gem 'country-select'
If I use semantic form select, it doesn't shows previously saved value. So, the following is not working properly:
=f.input :country, as: :select, collection: country_options_for_select
So have to use standard form elements to get working:
=f.select :country, collection: country_options_for_select
I found that this plugin works out of the box (note the underscore instead of the dash):
https://github.com/chrislerum/country_select
How do I set different css classes for the different selects(day, month) generate by:
<%= f.input :birthday, :as => :date, :discard_year => true,
:order => [:day, :month] %>
I just found a way to set the css class for the overall input.
It doesn't have to be simple_form. It can be regular rails code too.
Unfortunately, there is no simple way to solve it with select_date, even with simple-form. simple-form maps :as => 'date' to date_select.
Although you can split date_select into a select_day and select_month inputs and pass the respective css class at html_options for each input.
My question is how to set a field in rails form read only. The following is a selection box in quotes controller. Users are not allowed to change the selection.
<% #quote.test_items.each do |t| %>
<%= f.association :test_items, :label => false, :selected => t.id %>
<% end %>
The app uses simple_form. Thanks so much.
I've encountered a similar problem, thankfully, there is a simple resolution.
The basic issue is that if you use :disabled => true with simple_form you will not see that value back in the controller. When you pass an object from HTML form to later bind it to the model - you need all of those attributes. The :disabled => true however does not pass any such attribute.
The solution to this is to use :readonly => true - it will protect the field from user entry and it will still pass the param value back to the controller so you can bind everything to your model.
Good luck.
See https://github.com/plataformatec/simple_form/pull/367
I believe you'd just pass in :disabled => true. It's been my experience that options 'just work' with simple_form. So in your case:
<% #quote.test_items.each do |t| %>
<%= f.association :test_items, :label => false, :disabled => true, :selected => t.id %>
<% end %>
From the simple_form github repo:
It is also possible to give the :disabled option to SimpleForm, and it'll automatically mark the wrapper as disabled with a css class, so you can style labels, hints and other components inside the wrapper as well.
Yes, what #gk0r said, as it is documented here:
NOTE: The HTML options disabled, readonly, and multiple can all be treated as booleans. So specifying :disabled => true will give disabled="disabled".
*disabled will have slightly different behavior than readonly.
The top answers above are all wrong.
disabled attribute has a different behaviour than readonly.
read and compare them:
http://www.w3schools.com/tags/att_input_disabled.asp
Tip: Disabled elements in a form will not be submitted.
http://www.w3schools.com/tags/att_input_readonly.asp
The right answer is to use
:readonly => true
something like this:
<%= f.association :test_items, :label => false, :readonly => true, :selected => t.id %>
It's not clear to me if the association method accepts HTML options or not, but if it does, you can pass disabled: 'disable' to make it read-only with a fixed value.
I think you might be able to choose the fixed value by passing association as block, as shown in the association docs:
f.association :company do |c|
c.input :name, selected: 'selection'
c.input :type
end
As to whether or not the entire list can be read-only and still drop-down, the only solutions I see from google involve JS, for example:
http://techeyes.blogspot.com/2007/11/making-html-select-readonly.html