Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emberjs and Validation

Tags:

How are people handling client side validation and ember?

Is there anything out of the box or a plugin that handles validation or are people just rolling their own?

like image 240
dagda1 Avatar asked Jul 21 '12 05:07

dagda1


People also ask

What is Ember changeset?

The idea behind a changeset is simple: it represents a set of valid changes to be applied onto any Object ( Ember. Object , DS. Model , POJOs, etc).


2 Answers

https://github.com/dockyard/ember-validations might be useful. It also hooks up to Ember-easy-form

like image 115
Martin Stannard Avatar answered Nov 13 '22 04:11

Martin Stannard


I would extend Ember.TextField (or whatever input type your validating) and use classBinding with a computed property. Here is the sample: http://jsfiddle.net/caligoanimus/7UNRd/

template:

<script type="text/x-handlebars" >     {{view App.AlphaNumField         placeholder="alpha-numeric data only"         valueBinding="App.alphaNumInput"}} </script> 

application:

App = Ember.Application.create({     AlphaNumField:  Ember.TextField.extend({         isValid: function() {             return /^[a-z0-9]+$/i.test(this.get('value'));         }.property('value'),         classNameBindings: 'isValid:valid:invalid'     }) }); 
like image 43
caligoanimus Avatar answered Nov 13 '22 05:11

caligoanimus