Ajax submit: Clicking 'Submit' vs. hitting ENTER

Hi there,

Has anyone an idea why the below form

  • submits correctly when I click the ‘Submit’ button
  • but does call the ‘new’ action instead of ‘create’ when I hit ENTER?

<% form_remote_tag :html => { :action => url_for(:controller => ‘pages’,
:action => ‘create’) }
do -%>

<%= text_field :page, :title %>
<%= submit_to_remote ‘blah’, ‘Submit’, :url => {:controller =>
‘pages’,
:action => ‘create’}
%>

<% end -%>

Thanks a lot for any hints!
Tom

On 27 May 2010 18:24, Tom Ha [email protected] wrote:

<%= text_field :page, :title %>
<%= submit_to_remote ‘blah’, ‘Submit’, :url => {:controller =>
‘pages’,
:action => ‘create’}
%>

<% end -%>

Firstly it may be worth checking the html of the page is valid (view
the source in your browser and copy and paste the complete html into
the w3c html validator - find it with google if necessary).

Assuming html is valid is it possible that Enter is hitting a
different button or link on the page? Does the log give any clues?
I seem to remember a discussion here about this a little time ago, but
I don’t remember the result. A bit of searching here and googling may
be useful.

Colin

On Thu, May 27, 2010 at 1:03 PM, Colin L. [email protected]
wrote:

Assuming html is valid is it possible that Enter is hitting a
different button or link on the page? Does the log give any clues?

Besides the above, use FF/Firebug to

  1. confirm there are no JavaScript errors occurring
  2. compare the network traffic generated by each event

FWIW,

Hassan S. ------------------------ [email protected]
twitter: @hassan

On May 27, 10:24 pm, Tom Ha [email protected] wrote:

<%= text_field :page, :title %>
<%= submit_to_remote ‘blah’, ‘Submit’, :url => {:controller =>
‘pages’,
:action => ‘create’}
%>

<% end -%>

You should confirm that your page has multiple form_tags? as like
form within another(inner forms).
actions is going to the first form action when you are using 2 forms
in your page
You can try with the following
<%=javascript_include_tag “prototype”%>

<%= text_field :page, :title %> <%= submit_to_remote 'blah', 'Submit', :url => {:action => 'create'},:update=>"SS"%>

On May 27, 6:24 pm, Tom Ha [email protected] wrote:

<%= text_field :page, :title %>
<%= submit_to_remote ‘blah’, ‘Submit’, :url => {:controller =>
‘pages’,
:action => ‘create’}
%>

<% end -%>

Well it should be ok to have that submit tag just be a normal submit
tag. Secondly if my memory is correct, passing the html => :action
option is only for setting up a fallthrough for if the user doesn’t
have javascript (check what gets generated). You also need to say
something like form_remote_tag :url => {:controller => pages …

Fred

On May 27, 10:24 pm, Tom Ha [email protected] wrote:

<%= text_field :page, :title %>
<%= submit_to_remote ‘blah’, ‘Submit’, :url => {:controller =>
‘pages’,
:action => ‘create’}
%>

<% end -%>

You should confirm that your page has multiple form_tags? as like
form within another(inner forms).
actions is going to the first form action when you are using 2 forms
in your page
You can try with the following
<%=javascript_include_tag “prototype”%>

<%= text_field :page, :title %> <%= submit_to_remote 'blah', 'Submit', :url => {:action => 'create'},:update=>"SS"%>

On May 27, 10:24 pm, Tom Ha [email protected] wrote:

<%= text_field :page, :title %>
<%= submit_to_remote ‘blah’, ‘Submit’, :url => {:controller =>
‘pages’,
:action => ‘create’}
%>

<% end -%>

You should confirm that your page has multiple form_tags? as like
form within another(inner forms).
actions is going to the first form action when you are using 2 forms
in your page
You can try with the following
<%=javascript_include_tag “prototype”%>

<%= text_field :page, :title %> <%= submit_to_remote 'blah', 'Submit', :url => {:action => 'create'},:update=>"SS"%>

Thanks for all the feedback!

Fred’s nailed it and all other hints were instructive as well!