Hi there,
It’s 1.47 am and I am kinda tired of searching for answers now. I hope
someone would respond.
I have a javascript to validate date and display error message. I also
have an ajax form that returns the value of the form provided the dates
are in the correct format.
I notice if I use submit_tag onclick, the form displays the error
message AND submits the form. On the other hand, if I use input
type=“button,” the form displays the error properly first without
submitting the form, but when it submits the form, it’s no longer ajax
anymore (the result is displayed on a separate refreshed page).
My question: how to use submit_tag and prevents from submission if js
validation returns false?
<% form_remote_tag :update => ‘practiceResult’,
:loading =>
“$(‘indicator1’).show()”,
:complete =>
“$(‘indicator1’).hide()”,
:success =>
“set_blank(‘practice’)”,
:url =>
{:controller => ‘profiles’, :action => ‘add_practice’} do %>
<%= render :partial =>
‘profiles/practice_form’, :objects => @profiles_practice %>
<%= hidden_field_tag ‘practice_type’,
‘practice’ %>
<%= submit_tag “Add (ruby)”,
:onclick=>“validate_date(this.form, this.form.practice_start_date.value,
this.form.practice_end_date.value);” %>
<% end %>
Thanks.
Milton