Display inline errors with simple_form in a Bootstrap Ajax modal

3,659 views
Skip to first unread message

mcbsys

unread,
Nov 15, 2012, 7:44:31 PM11/15/12
to plataformate...@googlegroups.com
Is anyone aware of a comprehensive guide on using simple_form with a Bootstrap modal, especially getting the inline errors to work?

It seems the thing to do or error is re-render the entire form on the server (with errors), push that to the client as JavaScript, and use Ajax to inject it into the modal. I'm close, but it's looking at my JavaScript as a JSON variable and giving me a "JSON.parse: unexpected character" error. I've posted my current code here:

http://stackoverflow.com/questions/13408508/display-inline-errors-with-simple-form-in-a-bootstrap-ajax-modal

Is there a better way? I saw one article that recommends client-side validations, but it doesn't seem like that should be necessary.

Thanks,

Mark Berry
MCB Systems

Carlos Antonio da Silva

unread,
Nov 16, 2012, 7:04:24 AM11/16/12
to plataformate...@googlegroups.com
I think you have to enforce the dataType to be `html` so that it would not parse as JSON, but I may be wrong. I did it sometime ago, I have to check in an old project that's in my other computer, if I find it I'll post back here.
--
At.
Carlos Antonio
Message has been deleted

mcbsys

unread,
Nov 16, 2012, 6:46:52 PM11/16/12
to plataformate...@googlegroups.com
Found a very good article by a member of the Rails JQuery UJS core team:

Rails 3 Remote Links and Forms Part 2: Data-type (with jQuery)

http://www.alfajango.com/blog/rails-3-remote-links-and-forms-data-type-with-jquery/

"jQuery’s .ajax() method provides an optional parameter called dataType to specify the desired data-type of the response."

So data-type defines the response. It apparently has nothing to do with submitting data.

Since I'm trying to return a JavaScript file, I can either specify data-type = :script, or just leave it off and let it be inferred.

Still have other issues but I'm a step closer.

Mark Berry
MCB Systems

On Friday, November 16, 2012 2:45:26 PM UTC-8, mcbsys wrote:
Thanks Carlos. I was thinking it had to be dataType=JSON to properly encode the data when submitting the form. And it does work when the data is valid. It's when there are errors and I try to re-render the <div> that contains the form that I get into trouble.

Carlos Antonio da Silva

unread,
Nov 16, 2012, 7:20:19 PM11/16/12
to plataformate...@googlegroups.com
Nice blog post at a glance, already bookmarked to read later, thanks for sharing Mark.
--
At.
Carlos Antonio

Chris Beck

unread,
Dec 1, 2012, 10:08:48 AM12/1/12
to plataformate...@googlegroups.com
FWIW, after much research, I chose to use the https://github.com/bcardarella/client_side_validations gem as a general purpose validation pattern for my client-side UIs in both bootstrap and jquery mobile.  Like simple_form, c_s_v is very extensible (I use the bootstrap plugin) and very well documented. Plus c_s_v gives you a nice design pattern for writing custom validators for both client (local and remote) and server.  I wish I had done this sooner.
Reply all
Reply to author
Forward
0 new messages