Rails jquery datepicker can't find html - ruby-on-rails

I'm using the jquery-ui datepicker in a Rails app. I have 2 forms for entering data. One is a regular Rails view page and the other is a Bootstrap modal. The modal one isn't working.
This is the coffeescript (I'm assuming this will work for both):
$("#expense_exp_date").datepicker dateFormat: "yy-mm-dd"
This is the Rails view code and corresponding html:
<%= f.input :exp_date, :as => :string, :label => 'Date', :class => 'calendar hasDatepicker', :input_html => {:value => Date.today.to_s} %>
<input class="string required hasDatepicker" id="expense_exp_date" name="expense[exp_date]" size="50" type="text" value="2013-01-21">
This is the Bootstrap modal code and corresponding html:
<%= f.input :exp_date, :as => :string, :label => 'Date', :class => 'calendar hasDatepicker', :input_html => {:value => Date.today.to_s}, :input_html => {:style => 'width: 180px'} %>
<input class="string required" id="expense_exp_date" name="expense[exp_date]" size="50" style="width: 180px" type="text">
Why is "hasDatepicker" missing from the modal html?
Thanks!

Try to pass the class option inside the input_html Option hash:
<%= f.input :exp_date, :as => :string, :label => 'Date',
:input_html => {
:value => Date.today.to_s,
:class => 'calendar hasDatepicker'} %>

Related

how to add Active Admin form input :html {multiple => ""}?

ActiveAdmin form:
my problem: I can not get a form with multiple choice files(
I tried:
ActiveAdmin.register Foto do:
form :html => { :multipart => true } do |f|
f.inputs "Upload" do
f.input :foto, :as => :file
end
f.actions
end
end
this does not work, then I made a simple html page with two forms:
<!DOCTYPE doctype html>
<html>
<head>
</head>
<body>
<!--**not** work multiple choice files-->
<form accept-charset="UTF-8" action="#" enctype="multipart/form-data" method="post">
<input id="image" name="image" type="file"/>
</form>
<!--**great** work multiple choice files-->
<form accept-charset="UTF-8" action="#" method="post">
<input id="image" name="image" type="file" multiple=""/>
</form>
</body>
</html>
Question: how to add a property to multiple input field ?
I tried:
f.input :foto, :as => :file, :html => {:multiple => ""}
f.input :foto, :as => :file, :html => {:multiple => ""}
f.input :foto, :as => :file, :html => {"multiple" => "multiple"}
f.input :foto, :as => :file, :html => {:multiple => :multiple}
this does not work
help me, please.
You should use
f.input :foto, as: :file, input_html: { multiple: true }

Rails input_html being reapplied

In Rails 3.2 - I sometimes use :input_html on forms.
For example:
<%= f.input :assign_client, :label => 'Charge Client?', :input_html => {:checked => true} %>
If the user unchecked the box and submits the form and there are some validation errors, the check box gets checked again.
Is there a way to leave it unchecked?
Thanks for your help!
UDPATE1
I changed the code to this:
<% if params.has_key?(:assign_client) %>
<%= f.input :assign_client, :label => 'Charge Client?' %>
<% else %>
<%= f.input :assign_client, :label => 'Charge Client?', :input_html => {:checked => true} %>
<% end %>
But, that didn't work.
The params hash will contain the assign_client key if the checkbox was checked by the user. So, you could do something like this:
<%= f.input :assign_client, :label => 'Charge Client?', :input_html => { :checked => params.has_key?(:assign_client) } %>

Bootstrap markdown with Rails and Simple Form

I'm trying to add Bootstrap Markdown to a Rails app, using a gem. I am also trying to use simple_form to format the layout.
https://github.com/dannytatom/rails-bootstrap-markdown
Bootstrap Markdown requires a data-provide attribute, as shown in the html code from the project's github site: http://toopay.github.io/bootstrap-markdown/
<textarea name="content" data-provide="markdown" rows="10"></textarea>
But when I try to do this in my simple_form, I get an error: wrong number of arguments (0 for 1..2)
<%= simple_form_for(#essay) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :class %>
<%= f.input :title %>
<%= f.input :essay, :input_html => {:rows => 5, :placeholder => "Enter some text.", :class => "span6", :data-provide => "markdown" }%>
<%= f.input :status %>
</div>
Ruby doesn't accept a '-' in a symbol... You need to provide your data-provide as a string... Everything else looks okay. e.g.
<%= f.input :essay, :input_html => {:rows => 5, :placeholder => "Enter some text.", :class => "span6", "data-provide" => "markdown" }%>
Or, optionally I think you could also use the Rails data hash like so:
<%= f.input :essay, :input_html => {:rows => 5, :placeholder => "Enter some text.", :class => "span6", :data => {:provide => "markdown"} }%>
The latter method might be better if you're providing a lot of data attributes, but for a single attr the first seems more readable.

simple_form label to be column value

I am using simple_form in rails and have a situation where I want the label to be the value from another field. In this case that field is not to be changed and so I don't want to be on the form.
To explain a bit better I have two lines that look like
<%= f.input :name, :label => false, :disabled => true, :input_html => { :class => 'input-small' } %>
<%= f.input :status, :collection => ["Not started", "Passed", "Failed"], :include_blank => false, :label => false %>
What I'd like to do is have the first element to be the label of the second element. Now I could do this by having them inline, but I'd like them to be lined up with the other elements so that the labels and inputs are lined up.
so doing something like
<%= f.input :status, :collection => ["Not started", "Passed", "Failed"], :include_blank => false, :label => f.name %>
or
<%= f.input :status, :collection => ["Not started", "Passed", "Failed"], :include_blank => false, :label => {f.input :name, :label => false, :disabled => true} %>
Any thoughts on how to get around this?
Michael
'f.object' gets the object associated to that form and then you can get to the fields:
<%= f.select(:status, [["Not started","Not started"], ["Passed", "Passed"], ["Failed", "Failed"]]), :label => f.object.name %>
In the end I did indeed go for the inline option, which isn't ideal but did the job. However I had to do the following.
The main form set as a norm form
The block below that set as form-horizontal
then the subform partial defined as a none simple_form
<div class="control-group form-inline">
<div class="controls">
<%= f.text_field :name, :disabled => 'true', :size => 10 %>
<%= f.select(:status, [["Not started","Not started"], ["Passed", "Passed"], ["Failed", "Failed"]]) %>
</div>
</div>
If it was set as a simpleform the inline would not work as required. Again not perfect, and certainly not elegant, but worked

Adding a class to Formtastic radio button

I have a Formtastic radio button collection which is populated by a number of types:
<%= f.input :type_id, :validate => true, :as => :radio, :collection => Type.where(:object_type => 'Post') %>
However, I want to conditionally add a class to each choice, since some of the radio buttons need to be disabled depending on a certain condition.
For example, a :member_class => param would be ideal, but I don't believe it exists like :member_label and :member_value.
Does Formtastic have the ability to allow this?
<%= f.input :type_id, :validate => true, :as => :radio,
:collection => Type.where(:object_type => 'Post'),
:input_html => { :class => (:class_name if condition_goes_here) } %>
or
<%= f.input :type_id, :validate => true, :as => :radio,
:collection => Type.where(:object_type => 'Post'),
:input_html => { :disabled => (:disabled if condition_goes_here) } %>

Resources