Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-computed-validations

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-computed-validations

Lightweight validations library for ember.js focused on computed properties.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

ember-computed-validations Build Status Ember Observer Score

Lightweight validations library for ember.js focused on computed properties.

One of the most useful features in ember is computed properties. These can be particularly useful to determine the validity of a property without having to learn a new validations DSL. This library makes it easy to use them for validations by aggregating error messages for each property and by providing a mechanism to easily determine overall validity. In addition it gives you a place to easily specify error messages for each "validation" (computed property used for validation).

Because this library uses computed properties under the hood instead of observers or any other means, you can say goodbye to the days of calling validate() or any other hacks to get your validation back in sync.

Using ember-computed-validations

ember install ember-computed-validations

Example:

import ComputedValidationsMixin from 'ember-computed-validations/mixins/computed-validations';

export default Ember.Component.extend(ComputedValidationsMixin, {
  user: null,

  // validations
  firstNameNotEmpty: Ember.computed.notEmpty('user.firstName'),
  emailIsEmail: Ember.computed.match('user.email', /^.+@.+\..+$/),
  passwordsMatch: Ember.computed('user.password1', 'user.password2', function() {
    return this.get('user.password1') === this.get('user.password2');
  }),

  // declaring which validations validate which properties and their respective error messages
  computedValidations: {
    // properties to validate
    firstName: {
      // validations with error message to display if the validation is falsy
      firstNameNotEmpty: 'First name is a required field.'
    },
    lastName: {
      // validations do not need to be computed properties
      'user.lastName': 'Last name is a required field.'
    },
    email: {
      // create a dynamic error message by using a function
      emailIsEmail: function() {
        return `${this.get('user.email')} is not a valid email address.`;
      }
    },
    password: {
      // you can list multiple validations
      'user.password1': 'Please enter a password.',
      passwordsMatch: 'The password fields must match.'
    }
  }
});

You can use this mixin on any type of ember object: Ember.Component, DS.Model, Ember.Object, etc. It will add properties to your object so you can determine the state of validations easily:

component.get('computedErrors.firstName'); // ['First name is a required field.']
component.get('computedIsValid'); // false
component.get('computedIsInvalid'); // true

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

Keywords

FAQs

Package last updated on 03 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc