Reputation: 33
<%= form_tag do %>
<div class="container">
<div class="row">
<div class="input-field col s12">
<%= text_field_tag :sid , params[:sid], :length => 9 %>
<h6 class="grey-text" style="font-size: 1vw">Ex.570510XXX</h6>
<%= label_tag(:sid, "Student ID") %>
</div>
<div class="input-field col s6">
<%= text_field_tag :semester, params[:semester], :length => 1 %>
<%= label_tag(:semester, "Semester") %>
<h6 class="grey-text" style="font-size: 1vw">Ex.Term 2 = input 2</h6>
</div>
<div class="input-field col s6">
<%= text_field_tag :year, params[:year], :length => 2 %>
<%= label_tag(:year, "Year") %>
<h6 class="grey-text" style="font-size: 1vw">Ex.2558 = input 58</h6>
</div>
<br><br><br><br><br><br><br><br><br><br><br>
<div class="col s6">
<%= button_tag(value: 'Submit',class: "waves-effect waves-light btn right") do %>
Submit
<i class="material-icons right">send</i>
<% end %>
</div>
<div class="col s6">
<%= button_tag(value: 'CLEAR',type: 'reset',class: "waves-effect waves-light btn") do %>
CLEAR
<i class="material-icons right">delete</i>
<% end %>
</div>
</div>
i want to a button_tag type=reset to clear every page
it's work when i'm reset before submit. if i'm press submit it's not working.
try my page : http://timetable4cmu.herokuapp.com/
input: StudentID = 570510629, Semester=2, year=58 when you input and submit clear button will not working.
please help me!!
Upvotes: 1
Views: 787
Reputation: 2183
Yes, your form reset
button is not working after submission, I think( not sure) because it can't reset the default value(after submitting you show the form with populated value). You can manually update form data using js/jquery
( make input text data ''
empty string)
function resetForm(){
$('input[ name=sid]').val('');
$('input[ name=semester]').val('');
$('input[ name=year]').val('');
}
and call this method after with jquery
$('button[type=reset]').click(function(event){
event.preventDefault();
resetForm();
});
Upvotes: 1
Reputation: 411
If you don't want the parameters in the form after submit, then you should not pass the params in the form fields.
From this:
<%= text_field_tag :sid , params[:sid], :length => 9 %>
<%= text_field_tag :semester, params[:semester], :length => 1 %>
<%= text_field_tag :year, params[:year], :length => 2 %>
To:
<%= text_field_tag :sid , '', :length => 9 %>
<%= text_field_tag :semester, '', :length => 1 %>
<%= text_field_tag :year, '', :length => 2 %>
Upvotes: 0