Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6923363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:31:35+00:00 2026-05-27T10:31:35+00:00

I have a formtastic form like the following: = semantic_form_for @record, :remote => true,

  • 0

I have a formtastic form like the following:

= semantic_form_for @record, :remote => true, :id => 'my_form', :url => ...

Since I’m using :remote => true, I handle the response from the controller in javascript:

$('#my_form')
  .bind("ajax:beforeSend", function(evt, xhr, settings){

  })
  .bind("ajax:success", function(evt, data, status, xhr){
      $('#response').append(xhr.responseText);
  })
  .bind('ajax:complete', function(evt, xhr, status){

  });

With :remote => false, my form automatically displays field validation errors resulting from trying to save the record in the controller like so:

@record = Record.new(params[:record])
@record.save

How do I make the formtastic field validation errors appear with :remote => true, where I’m handling the response myself in javascript?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:31:36+00:00Added an answer on May 27, 2026 at 10:31 am

    Put the formtastic form in a view by itself.

    In the controller action that handles the posted form, you can re-“render” the view when the record save fails. When the view is rendered, formtastic will look at the errors field in @record and display the validation errors. If the save succeeds, you can render an empty string to indicate success. (A more complex response scheme is possible depending on what you need.)

      def save_record
        if request.xhr?               # form submitted using remote => true
          respond_with do |format|
            format.html do
              if @record.save
                # record saved successfully
                render :text => ""    # indicate success with empty response
              else                    # error saving record; send back form with validation errors marked
                render :template => '/path/to/record_form_view', :layout => false
              end
            end
          end
          return
        end
        #...
      end
    

    Then, in the client-side javascript, when the record fails to save, you can replace the existing form with the rendered view passed back from the controller.

    // reference: http://www.alfajango.com/blog/rails-3-remote-links-and-forms/
    function setup_record_form_bindings() {
      $('#record_form_id')
      .bind("ajax:beforeSend", function(evt, xhr, settings){
        var $submitButton = $(this).find('input[name="commit"]');
        $submitButton.get(0).value = "Submitting...";
      })
      .bind("ajax:success", function(evt, data, status, xhr){      
          if (xhr.responseText === "") {              // successful save
                                                      // do somethign appropriate here
          } else {                                    // error saving
            $('#record_form_id').remove();            // remove old form, to replace with form in responseText
            $('#record_form_parent_id').append(xhr.responseText);  // should be the newly rendered form (with validation errors shown)
            setup_record_form_bindings();
          }
      })
      .bind('ajax:complete', function(evt, xhr, status){
      });
    }
    setup_record_form_bindings();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form with Formtastic: = semantic_form_for @user, :url=> url_for(register_path), :html =>
So i have a form generated by formtastic and it's working : <%semantic_form_for(Model.new,:url=>{:action=>fooobar}) do
I have rails 3.1.3 and formtastic 2.0.2. I'm using the most basic form you
I would like to use formtastic to create form but I don't have a
I'm building a form in Rails3 and Formtastic. I have the following field: <%=
I have the following in a partial in a Rails 3.2 app using formtastic
I'm using ActiveAdmin and Formtastic. I have an invoice form that has a drop
i'm using formtastic i have the following before_filter :get_client, :except => [:index,:create] private def
I have a form built with formtastic, the code is <%= semantic_form_for @plan, :html
I'm using formtastic to collect information from a form and post dirctly to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.