I want submit a form via ajax only if i have a new record, so I''ve set: (I''m using simple_form) = simple_form_for @document, :html => { :multipart => true }, :remote => @document.new_record? ? true : false, do |f| = render ''shared/error_messages'', :object => @document = field_set_tag t(''document'') do .block .column.span-24 .inputs = f.input :name = f.input :description = f.input :doc, :as => :file = f.input :company_id, :input_html => { :value => params[:company_id] }, :as => :hidden if @document.new_record? .actions = f.button :submit It works if the validations are all ok but if a validation fails, I correct the error and then submit again, remote is no longer valid because, I think, new_record? return false. Isn''t it? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Nov 18, 2011 at 8:01 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want submit a form via ajax only if i have a new record, so I''ve set: > (I''m using simple_form) > > = simple_form_for @document, :html => { :multipart => true }, :remote > => @document.new_record? ? true : false, do |f| > = render ''shared/error_messages'', :object => @document > > = field_set_tag t(''document'') do > .block > .column.span-24 > .inputs > = f.input :name > = f.input :description > = f.input :doc, :as => :file > = f.input :company_id, :input_html => { :value => > params[:company_id] }, :as => :hidden if @document.new_record? > > .actions > = f.button :submit > > It works if the validations are all ok but if a validation fails, I > correct the error and then submit again, remote is no longer valid > because, I think, new_record? return false. >nope. if @document is not saved, then @document.new_record? should still return true. When you say you correct the error, you''re submitting the same form right? without page reload since you''re submitting via ajax so the form should still submit via ajax.> Isn''t it? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 November 2011 13:17, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Fri, Nov 18, 2011 at 8:01 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> I want submit a form via ajax only if i have a new record, so I''ve set: >> (I''m using simple_form) >> >> = simple_form_for @document, :html => { :multipart => true }, :remote >> => @document.new_record? ? true : false, do |f| >> = render ''shared/error_messages'', :object => @document >> >> = field_set_tag t(''document'') do >> .block >> .column.span-24 >> .inputs >> = f.input :name >> = f.input :description >> = f.input :doc, :as => :file >> = f.input :company_id, :input_html => { :value => >> params[:company_id] }, :as => :hidden if @document.new_record? >> >> .actions >> = f.button :submit >> >> It works if the validations are all ok but if a validation fails, I >> correct the error and then submit again, remote is no longer valid >> because, I think, new_record? return false. > > nope. if @document is not saved, then @document.new_record? should > still return true. When you say you correct the error, you''re submitting > the > same form right? without page reload since you''re submitting via ajax so > the form should still submit via ajax.I have strange behaviors. As you see the form has remote => true if model is a new record. But when I call submit the form is not submited via ajax. The controller respond_to :js and I have new.js.erb and create.js.erb files. Perhaps the multipart create a problem? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Nov 18, 2011 at 8:25 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 November 2011 13:17, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On Fri, Nov 18, 2011 at 8:01 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> I want submit a form via ajax only if i have a new record, so I''ve set: > >> (I''m using simple_form) > >> > >> = simple_form_for @document, :html => { :multipart => true }, :remote > >> => @document.new_record? ? true : false, do |f| > >> = render ''shared/error_messages'', :object => @document > >> > >> = field_set_tag t(''document'') do > >> .block > >> .column.span-24 > >> .inputs > >> = f.input :name > >> = f.input :description > >> = f.input :doc, :as => :file > >> = f.input :company_id, :input_html => { :value => > >> params[:company_id] }, :as => :hidden if @document.new_record? > >> > >> .actions > >> = f.button :submit > >> > >> It works if the validations are all ok but if a validation fails, I > >> correct the error and then submit again, remote is no longer valid > >> because, I think, new_record? return false. > > > > nope. if @document is not saved, then @document.new_record? should > > still return true. When you say you correct the error, you''re submitting > > the > > same form right? without page reload since you''re submitting via ajax so > > the form should still submit via ajax. > > I have strange behaviors. > As you see the form has remote => true if model is a new record. > But when I call submit the form is not submited via ajax. > The controller respond_to :js and I have new.js.erb and create.js.erb > files. > Perhaps the multipart create a problem? > >I didn''t read the code carefully but I think the :remote key-value pair should go inside the :html hash Let me know if that submits your form via ajax.> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 November 2011 17:05, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Fri, Nov 18, 2011 at 8:25 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> On 18 November 2011 13:17, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > >> > On Fri, Nov 18, 2011 at 8:01 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> I want submit a form via ajax only if i have a new record, so I''ve set: >> >> (I''m using simple_form) >> >> >> >> = simple_form_for @document, :html => { :multipart => true }, :remote >> >> => @document.new_record? ? true : false, do |f| >> >> = render ''shared/error_messages'', :object => @document >> >> >> >> = field_set_tag t(''document'') do >> >> .block >> >> .column.span-24 >> >> .inputs >> >> = f.input :name >> >> = f.input :description >> >> = f.input :doc, :as => :file >> >> = f.input :company_id, :input_html => { :value => >> >> params[:company_id] }, :as => :hidden if @document.new_record? >> >> >> >> .actions >> >> = f.button :submit >> >> >> >> It works if the validations are all ok but if a validation fails, I >> >> correct the error and then submit again, remote is no longer valid >> >> because, I think, new_record? return false. >> > >> > nope. if @document is not saved, then @document.new_record? should >> > still return true. When you say you correct the error, you''re >> > submitting >> > the >> > same form right? without page reload since you''re submitting via ajax so >> > the form should still submit via ajax. >> >> I have strange behaviors. >> As you see the form has remote => true if model is a new record. >> But when I call submit the form is not submited via ajax. >> The controller respond_to :js and I have new.js.erb and create.js.erb >> files. >> Perhaps the multipart create a problem? >> > > I didn''t read the code carefully but I think the :remote key-value pair > should go inside the :html hash > Let me know if that submits your form via ajax.I''ve changed to: = simple_form_for @document, :html => { :multipart => true, :remote => @document.new_record? ? true : false} do |f| = render ''shared/error_messages'', :object => @document = field_set_tag t(''document'') do .block .column.span-24 .inputs = f.input :name = f.input :description = f.input :doc, :as => :file = f.input :company_id, :input_html => { :value => params[:company_id] }, :as => :hidden if @document.new_record? .actions = f.button :submit but still doesn''t work via ajax. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 November 2011 18:13, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 November 2011 17:05, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> On Fri, Nov 18, 2011 at 8:25 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> On 18 November 2011 13:17, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> > >>> > >>> > On Fri, Nov 18, 2011 at 8:01 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >> >>> >> I want submit a form via ajax only if i have a new record, so I''ve set: >>> >> (I''m using simple_form) >>> >> >>> >> = simple_form_for @document, :html => { :multipart => true }, :remote >>> >> => @document.new_record? ? true : false, do |f| >>> >> = render ''shared/error_messages'', :object => @document >>> >> >>> >> = field_set_tag t(''document'') do >>> >> .block >>> >> .column.span-24 >>> >> .inputs >>> >> = f.input :name >>> >> = f.input :description >>> >> = f.input :doc, :as => :file >>> >> = f.input :company_id, :input_html => { :value => >>> >> params[:company_id] }, :as => :hidden if @document.new_record? >>> >> >>> >> .actions >>> >> = f.button :submit >>> >> >>> >> It works if the validations are all ok but if a validation fails, I >>> >> correct the error and then submit again, remote is no longer valid >>> >> because, I think, new_record? return false. >>> > >>> > nope. if @document is not saved, then @document.new_record? should >>> > still return true. When you say you correct the error, you''re >>> > submitting >>> > the >>> > same form right? without page reload since you''re submitting via ajax so >>> > the form should still submit via ajax. >>> >>> I have strange behaviors. >>> As you see the form has remote => true if model is a new record. >>> But when I call submit the form is not submited via ajax. >>> The controller respond_to :js and I have new.js.erb and create.js.erb >>> files. >>> Perhaps the multipart create a problem? >>> >> >> I didn''t read the code carefully but I think the :remote key-value pair >> should go inside the :html hash >> Let me know if that submits your form via ajax. > > I''ve changed to: > > = simple_form_for @document, :html => { :multipart => true, :remote => > @document.new_record? ? true : false} do |f| > = render ''shared/error_messages'', :object => @document > > = field_set_tag t(''document'') do > .block > .column.span-24 > .inputs > = f.input :name > = f.input :description > = f.input :doc, :as => :file > = f.input :company_id, :input_html => { :value => > params[:company_id] }, :as => :hidden if @document.new_record? > > .actions > = f.button :submit > > but still doesn''t work via ajax.I''ve noticed that if I don''t fill the file field then if I create a new document but without attaching any file then ajax works. If I attach a file in the file field then ajax doesn''t work. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 November 2011 18:28, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 November 2011 18:13, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 18 November 2011 17:05, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> >>> On Fri, Nov 18, 2011 at 8:25 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>> On 18 November 2011 13:17, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> > >>>> > >>>> > On Fri, Nov 18, 2011 at 8:01 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >> >>>> >> I want submit a form via ajax only if i have a new record, so I''ve set: >>>> >> (I''m using simple_form) >>>> >> >>>> >> = simple_form_for @document, :html => { :multipart => true }, :remote >>>> >> => @document.new_record? ? true : false, do |f| >>>> >> = render ''shared/error_messages'', :object => @document >>>> >> >>>> >> = field_set_tag t(''document'') do >>>> >> .block >>>> >> .column.span-24 >>>> >> .inputs >>>> >> = f.input :name >>>> >> = f.input :description >>>> >> = f.input :doc, :as => :file >>>> >> = f.input :company_id, :input_html => { :value => >>>> >> params[:company_id] }, :as => :hidden if @document.new_record? >>>> >> >>>> >> .actions >>>> >> = f.button :submit >>>> >> >>>> >> It works if the validations are all ok but if a validation fails, I >>>> >> correct the error and then submit again, remote is no longer valid >>>> >> because, I think, new_record? return false. >>>> > >>>> > nope. if @document is not saved, then @document.new_record? should >>>> > still return true. When you say you correct the error, you''re >>>> > submitting >>>> > the >>>> > same form right? without page reload since you''re submitting via ajax so >>>> > the form should still submit via ajax. >>>> >>>> I have strange behaviors. >>>> As you see the form has remote => true if model is a new record. >>>> But when I call submit the form is not submited via ajax. >>>> The controller respond_to :js and I have new.js.erb and create.js.erb >>>> files. >>>> Perhaps the multipart create a problem? >>>> >>> >>> I didn''t read the code carefully but I think the :remote key-value pair >>> should go inside the :html hash >>> Let me know if that submits your form via ajax. >> >> I''ve changed to: >> >> = simple_form_for @document, :html => { :multipart => true, :remote => >> @document.new_record? ? true : false} do |f| >> = render ''shared/error_messages'', :object => @document >> >> = field_set_tag t(''document'') do >> .block >> .column.span-24 >> .inputs >> = f.input :name >> = f.input :description >> = f.input :doc, :as => :file >> = f.input :company_id, :input_html => { :value => >> params[:company_id] }, :as => :hidden if @document.new_record? >> >> .actions >> = f.button :submit >> >> but still doesn''t work via ajax. > > I''ve noticed that if I don''t fill the file field then if I create a > new document but without attaching any file then ajax works. > If I attach a file in the file field then ajax doesn''t work.I seems that traditional upload does not work via ajax. I''ve resolved via remotipart gem. http://www.alfajango.com/blog/remotipart-rails-gem/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 18, 5:28 pm, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve noticed that if I don''t fill the file field then if I create a > new document but without attaching any file then ajax works. > If I attach a file in the file field then ajax doesn''t work.Files can''t be sent over ajax. There is the iframe trick which looks like ajax (in that there is no full page reload) but is in fact just a ''normal'' form submission. Some js libraries (e.g. jquery.form if my memory is correct) will even do this automatically for you. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 November 2011 18:47, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Nov 18, 5:28 pm, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> I''ve noticed that if I don''t fill the file field then if I create a >> new document but without attaching any file then ajax works. >> If I attach a file in the file field then ajax doesn''t work. > > Files can''t be sent over ajax. There is the iframe trick which looks > like ajax (in that there is no full page reload) but is in fact just a > ''normal'' form submission. Some js libraries (e.g. jquery.form if my > memory is correct) will even do this automatically for you.I''ve resolved with remotipart gem. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.