Validating elements created via JS

I have a link on a form that allows for infinite new records to be
created.
i.e. Clicking “Add new record” basically renders the _new partial and
appends it to a div.

The model contains validates_uniqueness_of and validates_presence_of a
few fields.

This is all well and good, however, when validation fails at the model
level, the users don’t get any feedback or explanation as to why the
creation of the model failed.

Is there a technique for validating these types of records? and giving
the user some sort of feedback?

TIA

On Mon, Jun 16, 2008 at 6:04 PM, Luke G.
[email protected] wrote:

level, the users don’t get any feedback or explanation as to why the
creation of the model failed.

Is there a technique for validating these types of records? and giving
the user some sort of feedback?

TIA

Can you provide some examples of how/why it would fail at the model
level? (error messages if any).

Anthony E.
408-656-2473
http://anthony.ettinger.name

Anthony E. wrote:

Can you provide some examples of how/why it would fail at the model
level? (error messages if any).

It fails simply because the new record is not valid, i.e. missing a
field, or a a field does not contain a unique value.

Hi Luke,

On 17.6.2008, at 4.04, Luke G. wrote:

level, the users don’t get any feedback or explanation as to why the
creation of the model failed.

How so? Are you sending the form via Ajax? If yes, do you use
Ajax.Request or Updater? Anyway, you have plenty of options. If you
are using Ajax, you can use RJS (or return plain javascript) that
replaces the form with one with all the error messages. It can also
add another error message to the page. If you’re not using ajax, just
render the form again just like the standard resource scaffolding does
and it will display the errors.

Is there a technique for validating these types of records? and giving
the user some sort of feedback?

Well, you must send the data to the server, right? So you have exactly
the same mechanisms as always at your disposal. Only relaying them to
the UI is a bit different and perhaps trickier.

//jarkko


Jarkko L.
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi