I have search field based on date entered.
The problem is whenever I am submitting the form then searched results comes good but search string disappears from the field as the page reloaded.
Can anyone tell me how to persist the search string in the field.
I am using ruby form and below is the code..
<%=form_for :messages, url: url_for( :controller => :time_sheets, :action => :late ), :html => { :id => "submitForm1" } do |f| %>
<div class="field">
<tr>
<td> From Date <%= f.text_field :leaveFrom, :id => 'datepicker2', :class => 'phcolor','data-validation' =>'required', :readonly => true %></td>
<td> To Date <%= f.text_field :leaveTo, :id => 'datepicker7', :class => 'phcolor', :readonly => true %></td>
<td >Late Time<%= f.text_field :on_duty, :id => 'timepicker5' %></td>
<div class="actions">
<td style="position: absolute;right: 178px;"><input type="button" class="btn btn-primary" id="submitid" tabindex="7" value="Go"></td>
</div>
</tr>
</div>
<% end %>
Your code form_for :messages
suggests that there is an instance variable @messages
, which holds the data of the fields in the form. Is there a valid @messages
?
If you don't have Model for messages, I think of a simple workaround. You can add this to the action:
@messages = OpenStruct.new(params[:messages])
Or, just replace form_for
with form_tag
, and set value of each fields from params. form_for
"creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields.", which is not suitable here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With