Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resetting the value of fields after submitting the ruby form

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 %>
like image 690
yaswant singh Avatar asked Nov 16 '12 11:11

yaswant singh


1 Answers

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.

like image 179
Yanhao Avatar answered Oct 11 '22 14:10

Yanhao