# Validating elements created via JS

**URL:** <https://www.ruby-forum.com/t/validating-elements-created-via-js/140647>\
**Category:** Deployment\
**Created:** [June 17, 2008, 3:04am UTC](https://www.ruby-forum.com/t/validating-elements-created-via-js/140647 "2008-06-17T03:04:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [June 17, 2008, 3:04am UTC](https://www.ruby-forum.com/t/validating-elements-created-via-js/140647/1 "2008-06-17T03:04:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [June 17, 2008, 3:15am UTC](https://www.ruby-forum.com/t/validating-elements-created-via-js/140647/2 "2008-06-17T03:15:54Z")

</div>

On Mon, Jun 16, 2008 at 6:04 PM, Luke G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://anthony.ettinger.name)

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [June 17, 2008, 3:20am UTC](https://www.ruby-forum.com/t/validating-elements-created-via-js/140647/3 "2008-06-17T03:20:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [June 17, 2008, 9:28am UTC](https://www.ruby-forum.com/t/validating-elements-created-via-js/140647/4 "2008-06-17T09:28:16Z")

</div>

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.

> **[jlaine.net](https://jlaine.net/)**
>
> Your freedom to carry a gun messes with my freedom to walk around without fear. Your freedom to “stand your ground” with force is at odds with my …

> **[Home](https://dotherightthing.com/)**
>
> do the right thing

[http://www.railsecommerce.com](http://www.railsecommerce.com)  
[http://odesign.fi](http://odesign.fi)
