Giter Club home page Giter Club logo

ember-model-validator's Introduction

Ember model validator

Download count all time CI Ember Observer Score

Add validations to your Ember Data models on an explicit and easy way, without a bunch a validations files around or complicated structure.

This README outlines the details of collaborating on this Ember addon.

Purpose

This Ember addon was born from the necessity of having a validation support for models similar to Active Record Validations on the Ruby on Rails land.

Installation

Install Ember-model-validator is easy as:

npm install ember-model-validator --save-dev or yarn add ember-model-validator --dev

Usage

Ember-model-validator provides a decorator to be included in your models for adding validation support. This decorator can be imported from your app's namespace (e.g. import { modelValidator, objectValidator } from 'ember-model-validator'; in your models).

By including Ember-model-validator's decorator into your model, this will have a validate function available, it is a synchronous function which returns either true or false.

You can also pass an option hash for excluding or forcing certain attributes to be validated, and to prevent errors to be added.

// Using `except`
myModel.validate({ except: ['name', 'cellphone'] });

// Using `only`
myModel.validate({ only: ['favoriteColor', 'mainstreamCode'] });

// Using `addErrors`
myModel.validate({ addErrors: false });
// ^ This will validate the model but won't add any errors.

To target specific validations when using except/only, pass the validations' names along the attribute's name:

// This runs all validations, except name's presence and length validations and
// any email validations.
// Other name validations are still run.
myModel.validate({ except: ['name:presence,length', 'email'] });

Usage Example

import Model, { attr } from '@ember-data/model';
import { modelValidator } from 'ember-model-validator';

@modelValidator
export default class MyModel extends Model {
  @attr('string') fullName;
  @attr('string') fruit;
  @attr('string') favoriteColor;

  validations = {
    fullName: {
      presence: true
    },
    fruit: {
      presence: true
    },
    favoriteColor: {
      color: true
    }
  };
}

After setting the validations on your model you will be able to:

import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class MyController extends Controller {
  @action
  async saveFakeModel() {
    const fakeModel = this.model;

    if (fakeModel.validate()) {
      await fakeModel.save();
    } else {
      console.log({ errors: fakeModel.get('errors') });
    }
  }
}

Or Usage in non Model(Controller, Componente, Object ...) Example

import Component from '@ember/component';
import { objectValidator } from 'ember-model-validator';

@objectValidator
export default class MyComponent extends Component {
  test = 'ABC',

  validations = {
    test: {
      presence: true
    }
  }
};

TypeScript

import Model, { attr } from '@ember-data/model';

import { modelValidator, type ValidationsConfig, type ValidatedModel } from 'ember-model-validator';

// https://github.com/microsoft/TypeScript/issues/4881
interface MyModel extends ValidatedModel, Model {}

@modelValidator
class MyModel extends Model {
  @attr('string') declare name: string;

  validations: ValidationsConfig = {
    name: {
      presence: true,
    },
    email: {
      presence: true,
      email: true,
    },
  };
}

export default MyModel;

declare module 'ember-data/types/registries/model' {
  export default interface ModelRegistry {
    'my-model': MyModel;
  }
}

Compatibility

  • ember-sourceand ember-data v3.28 or above

Validators

Common options

All validators accept the following options

  • message option. Overwrites the default message, it can be a String (with a {value} in it for value interpolation) or a function that returns a string.
  • errorAs option. Sets the key name to be used when adding errors (default to property name).
  • allowBlank option. If set to true and the value is blank as defined by Ember.isBlank, all other validations for the field are skipped.
  • if option. Validates only when the function passed returns true. function(key,value, _this){...}.

Presence

A value is not present if it is empty or a whitespace string. It uses Ember.isBlank method. This can be also used on async belongsTo relations.

validations = {
  name: {
    presence: true;
  }
}

Acceptance

These values: ['1', 1, true] are the acceptable values. But you can specify yours with the accept option.

validations = {
  acceptConditions: {
    acceptance: {
      accept: 'yes';
    }
  }
}

The accept option receives either a string or an array of acceptable values.

Absence

Validates that the specified attributes are absent. It uses Ember.isPresent method.

validations = {
  login: {
    absence: true;
  }
}

Format

Specify a Regex to validate with. It uses the match() method from String.

  validations = {
    legacyCode:{
      format: { with: /^[a-zA-Z]+$/ }
    }
  }

Length

Specify the lengths that are allowed.

Options
  • A number. The exact length of the value allowed (Alias for is).
  • An array. Will expand to minimum and maximum. First element is the lower bound, second element is the upper bound.
  • is option. The exact length of the value allowed.
  • minimum option. The minimum length of the value allowed.
  • maximum option. The maximum length of the value allowed.
  validations = {
    socialSecurity: {
      length: 5
    },
    nsaNumber: {
      length: [3, 5]
    },
    chuncaluchoNumber: {
      length: { is: 10, message: 'this is not the length of a chuncalucho' }
    },
    hugeName:{
      length: {
        minimum: 3,
        maximum: 5
      }
    },
    smallName:{
      length: {
        maximum: {
          value: 3,
          message: 'should be smaller'
        }
      }
    }
  }

Email

Validates the proper format of the email.

  validations = {
    email: {
      email: true
    }
  }

ZipCode

The value must be a correct zipcode. The countryCode is optional and defaults to 'US'.

Countries supported and regular expressions used can be found in postal-codes-regex.js

Options
  • countryCode option. The code of the country for which the postal code will be validated.
validations = {
  postalCode: {
    // If no countryCode is specified, 'US' is used as default
    zipCode: true;
  }
}
validations = {
  postalCodeUK: {
    zipCode: {
      countryCode: 'UK';
    }
  }
}

Hex Color

The value must be a correct Hexadecimal color.

validations = {
  favoriteColor: {
    color: true;
  }
}

Subdomain

The value must a well formatted subdomain. Here you can also specify reserved words.

validations = {
  mySubdomain: {
    subdomain: {
      reserved: ['admin', 'blog'];
    }
  }
}

URL

The value must a well formatted URL.

validations = {
  myBlog: {
    URL: true;
  }
}

Inclusion

The value has to be included in a given set.

  validations = {
    name:{
      inclusion: { in: ['Jose Rene', 'Aristi Gol', 'Armani'] }
    }
  }

Exclusion

The value can't be included in a given set.

  validations = {
    name:{
      exclusion: { in: ['Gionvany Hernandez', 'Wilder Medina'] }
    }
  }

Match

Specify the attribute to match with.

Options
  • A string. The name of the attribute to match with (Alias for attr).
  • attr option. The name of the attribute to match with.
  validations = {
    email:{
      match: 'confirmationEmail'
    },
    password:{
      match: {
        attr: 'passwordConfirmation',
        message: 'sup, it is not the same!'
      }
    }
  }

Numericality

The value has to have only numeric values.

Options
  • onlyInteger option. The value must be an integer.
  • greaterThan option. The value must be greater than the supplied value.
  • greaterThanOrEqualTo option. The value must be greater or equal to the supplied value.
  • equalTo option. The value must be equal to the supplied value.
  • lessThan option. The value must be less than the supplied value.
  • lessThanOrEqualTo option. The value must be less or equal to the supplied value.
  • odd option. The value must be odd.
  • even option. The value must be even.
validations = {
  lotteryNumber: {
    numericality: true;
  }
}

Date

The value must be a Date object or a string that produces a valid date when passed to the Date constructor.

Options
  • before option. The value must be before the supplied date.
  • after option. The value must be after the supplied date.
  validations = {
    birthDate: {
      date: {
        before: new Date()
      }
    },
    signupDate: {
      date: {
        after: '2015-01-01'
      }
    }
  }

Custom

Define a custom callback function to validate the model's value. The validation callback is passed 3 values: the key, value, model's scope. return true (or a truthy value) to pass the validation, return false (or falsy value) to fail the validation.

  validations = {
    lotteryNumber: {
      custom: function(key, value, model){
        return model.get('accountBalance') > 1 ? true : false;
      }
    }
  }

this has the same action as above except will use a custom message instead of the default.

  validations = {
    lotteryNumber: {
      custom: {
        validation: function(key, value, model){
          return model.get('accountBalance') > 1 ? true : false;
        },
        message: 'You can\'t win off of good looks and charm.'
      }
    }
  }

to have multiple custom validation functions on the same property, give 'custom' an array of either of the two syntax above.

validations = {
  lotteryNumber: {
    custom: [
      {
        validation: function(key, value, model) {
          return model.get('accountBalance') > 1 ? true : false;
        },
        message: "You can't win off of good looks and charm."
      },
      {
        validation: function(key, value, model) {
          return model.get('accountBalance') > 1 ? true : false;
        },
        message: "You can't win off of good looks and charm."
      }
    ];
  }
}

Password

A set of validators which are especially useful for validating passwords. Be aware that these all of these password-aimed validations will work standalone and carry the same common options with the rest of the validations. They don't only work for passwords!

  • mustContainCapital (capital case character).
  • mustContainLower (lower case character).
  • mustContainNumber
  • mustContainSpecial
  • length (explained in-depth above).
validations = {
  password: {
    presence: true,
    mustContainCapital: true,
    mustContainLower: true,
    mustContainNumber: true,
    mustContainSpecial: {
      message: 'One of these characters is required: %@',
      acceptableChars: '-+_!@#$%^&*.,?()'
    },
    length: {
      minimum: 6
    }
  },
  someOtherThing: {
    mustContainSpecial: true
  }
}

Relations

This validator will run the validate() function for the specific relation. If it's a DS.hasMany relation then it will loop through all objects.

Note: The relations have to be embedded or the promise has to be already resolved.

  validations = {
    myHasManyRelation:{
      relations: ['hasMany']
    },
    myBelongsToRelation:{
      relations: ['belongsTo']
    }
  }

Using function to generate custom message

You can pass a function to generate a more specific error message. Some scenarios are:

  • When the message varies depending of the attribute value.
  • When you want to use model attributes in the message.

The message function receives the attribute name, the value of the attribute and the model itself.

NOTE: If the function doesn't return a string the default message is going to be used.

Example
import Model, { attr } from '@ember-data/model';
import { modelValidator } from 'ember-model-validator';

@modelValidator
export default class MyModel extends Model {
  @attr('number', { defaultValue: 12345 }) otherCustomAttribute;

  validations = {
    otherCustomAttribute: {
      custom: {
        validation: function(key, value) {
          return value.toString().length === 5 ? true : false;
        },
        message: function(key, value, _this) {
          return key + ' must have exactly 5 digits';
        }
      }
    }
  };
}

I18n

Set validatorDefaultLocale in your config enviroment a language, for now it's possible use 'en', 'fr', 'es', 'uk', 'hu', 'sr', 'sr-cyrl' or 'pt-br', default is 'en';

//config/environment.js
...
  ENV:{
    ...
    APP:{
      validatorDefaultLocale: 'pt-br'
    }
    ...
  }
...

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

See the Contributing guide for details.

ember-model-validator's People

Contributors

adriguy avatar andsmedeiros avatar bladams avatar charlesfries avatar clairton avatar cvx avatar davidstevens37 avatar dependabot[bot] avatar dmuneras avatar edymerchk avatar esbanarango avatar greenkeeper[bot] avatar kariavka avatar leooo avatar lorcan avatar michaelw8 avatar miguelcobain avatar nbrysondev avatar sduquej avatar sethbrasile avatar sinankeskin avatar vfuto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-model-validator's Issues

Validation with inherit

Hi,

I have a model 'property' and 'flat'.
Flat inherits from property, but when i declare validations in both, only 'Flat' validators show, because they are rewritten.
How can I use validations from the parent in the child class?

Non-async relations are not validated correctly

Validations for related models are not run when the relationship is defined like DS.hasMany('related-model', {async: false})

I believe this is a regression introduced in this commit. I think in this case the related objects are not wrapped in a proxy so the content property is undefined.

I am currently using ember-data 2.8.1

Improve Numericality validator.

This validator should accept the same options as the Active Record Numericality validator.

  • only_integer
  • greater_than - Specifies the value must be greater than the supplied value. The default error message for this option is "must be greater than %{count}".
  • greater_than_or_equal_to - Specifies the value must be greater than or equal to the supplied value. The default error message for this option is "must be greater than or equal to %{count}".
  • equal_to - Specifies the value must be equal to the supplied value. The default error message for this option is "must be equal to %{count}".
  • less_than - Specifies the value must be less than the supplied value. The default error message for this option is "must be less than %{count}".
  • less_than_or_equal_to - Specifies the value must be less than or equal the supplied value. The default error message for this option is "must be less than or equal to %{count}".
  • odd - Specifies the value must be an odd number if set to true. The default error message for this option is "must be odd".
  • even - Specifies the value must be an even number if set to true. The default error message for this option is "must be even".

Issues when dealing with ember data states

in https://github.com/esbanarango/ember-model-validator/blob/master/addon/mixins/model-validator.js#L38

you are making a transition to the state updated.uncommitted and that set model properties to isNew == false and isDirty == true breaking the API like this: https://gist.github.com/sescobb27/5becc19ba451a18f5e15

a workaround to fix that problem is this, but it isn't generic for all situations.

if (!order.get('id')) {
  if (order.get('currentState.stateName') === 'root.loaded.updated.uncommitted') {
    order.transitionTo('loaded.created.uncommitted');
  }
  return order.save().then(deferred.resolve);
}

I think you should save the previous state of the model, and when the model is valid again reset that state

An in-range update of ember-ajax is breaking the build 🚨

The devDependency ember-ajax was updated from 3.1.2 to 3.1.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-ajax is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 3 commits.

  • 430d11c chore(release): 3.1.4
  • ba9a87d test: add test case around relative URL conversion
  • daf8319 Revert "fix: don't append leading '/' when building url"

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Length : different messages for "too long" and "too short"

Hello there!
First, let me thank you for this very good addon!

Concerning error messages for the length constraint, is there a way to have different messages for minimum and maximum?
Something like this would be great:

length: {
    minimum: {
        value: 3,
        message: 'form.errors.tooShort'
    }
}

An in-range update of eslint-plugin-ember is breaking the build 🚨

The devDependency eslint-plugin-ember was updated from 6.9.1 to 6.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-ember is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v6.10.0

πŸš€ Enhancement

  • #473 Add new no-incorrect-calls-with-inline-anonymous-functions rule (@raycohen)

πŸ› Bug Fix

  • #476 Add allowDynamicKeys option (default true) to require-computed-property-dependencies rule (@bmish)

Committers: 2

Commits

The new version differs by 7 commits.

  • 590cf98 v6.10.0
  • 46502cf Update CHANGELOG
  • 2e0469e Merge pull request #473 from raycohen/no-inline-anonymous-functions-to-schedule-once
  • 434b44d Merge pull request #476 from bmish/require-computed-property-dependencies-allowDynamicKeys-option
  • 5a9a0fe Add new no-incorrect-calls-with-inline-anonymous-functions rule
  • 55537f6 build(deps): bump ember-rfc176-data from 0.3.10 to 0.3.11 (#478)
  • 2733279 fix: add allowDynamicKeys option (default true) to require-computed-property-dependencies rule

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

ember-model-validator does not show anything

In the model I did like this:

import Ember from 'ember';

import Validator from 'ember-model-validator/mixins/model-validator';

export default Model.extend(Validator,{
  login: attr(),

  password: attr(),

 validations: {
    login: {
       presence: true
    },  
   password: {
     presence: true     
   }
  },

});

In the template.hbs I do something like this:

        <table>
             <tbody>
                 <tr>               
                    <td>{{input value=login}}</td>         
                    <td>{{input value=password}}</td>       
                </tr>
             </tbody>
         </table>

It does not show anything when I try to submit empty login or password.

Do I need to do something else ?

A Subclass' validations override the superclass' validations

To reproduce:

on super class:

  • validate one field

on sub class:

  • validate a different field

test:

  • have an instance of the sub class
  • do something that you would expect to cause both validations to fail
  • there is only an error for the subclass's validation, and not the superclass

Is there something similar to a conditional validation?

I need to validate a field only if another attribute has an specific value and I don't know if the library has this option.

i.e. something like this:

validations: {
  images: {
    presence: true,
    validateIf: function () { return 'gallery' === this.get('type'); }
  }
}

I know I can do it with customValidators so I can solve it that way right but it feels better this way because I can reuse the base validations of the library. Does this exists? If not, I can check the code and add it with a PR.

An in-range update of ember-cli-babel is breaking the build 🚨

The dependency ember-cli-babel was updated from 7.13.0 to 7.13.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-cli-babel is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for Release 7.13.1

πŸ› Bug Fix

  • #311 Include decorator and class field plugins after TypeScript, if present (@dfreeman)

πŸ“ Documentation

Committers: 2

Commits

The new version differs by 5 commits.

  • a72f8b0 Release 7.13.1
  • 0d4dcc3 Include decorator and class field plugins after TypeScript, if p… (#311)
  • e08b59d Include decorator and class field plugins after TypeScript, if present
  • bc0dee4 README: Update an outdated link (#309)
  • 3f6e108 README: Update an outdated link

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Document how to use the error-list in a template

I have set out to give ember-model-validator a serious try-out. It would be very helpful for me, if the documentation included an example (best practice) about how to use the error-list in a template.

For instance, look at the example at http://esbanarango.github.io/ember-model-validator/#/validators/length.

image

Here, it is possible to trigger several errors at the same time - great!

How do you relate errors for a specific model attribute to the field displaying this attribute? Are you using computed properties**?**

How do you make the error-messages immediately disappear from display and error-list, when starting to type something into a specific error-prone field, while all other errors keeps existing in the error-list and keeps being displayed**?**

DEPRECATION : Ember.String.fmt is deprecated use ES6 template strings instead

Using Ember 2.0.0 with Ember Data 2.1.0 and ember-model-validator I get a warning when validating numericality.

numericality: {
  allowBlank: true,
  greaterThanOrEqualTo: 0,
  lessThanOrEqualTo: 30
}
DEPRECATION: Ember.String.fmt is deprecated, use ES6 template strings instead. [deprecation id: ember-string-utils.fmt] See https://babeljs.io/docs/learn-es6/#template-strings for more details.
        at Object.fmt (http://localhost:4200/assets/vendor.js:44511:29)
        at _validateNumericality (http://localhost:4200/assets/vendor.js:167958:88)

In these lines is where the situation occurs.

We have an API that uses a `locale` property

There are a bunch of pre-existing code that uses the locale property of the model:

// my-model
export default Model.extend(Validator, {
  locale: attr('string'),
  ...
})

This conflicts with the locale property defined here: https://github.com/esbanarango/ember-model-validator/blob/master/addon/mixins/model-validator.js#L31-L38

There are obvious workarounds:

  • monkey-patch Validator
  • use myLocale: attr('string', { key: 'locale' }) and update all existing code

In general, Ember addons tend to be very aggressive with claiming keys in users' namespaces (see emberjs/data#973), so this code is idiomatic.

But what's the suggested workaround?

Also posting so that anyone else with the problem can find it (and a solution, if there is one).

cc @rwwagner90 @jblakeman

Emtpy value as invalid property

HI,
I noticed that if I have:

logoUrl: {
  URL:true,
},

It required from me value cuz empty string or null is always invalid. Is there an option for make any empty string or null always valid?

Internationalization support (i18n)?

Hi

Is there a way to add i18n support for the default error messages (like "can't be blank"). Especially if it would work with ember-i18n :) ?

An in-range update of ember-cli-inject-live-reload is breaking the build 🚨

The devDependency ember-cli-inject-live-reload was updated from 1.8.2 to 1.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-cli-inject-live-reload is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 9 commits.

  • 60b2ba2 1.10.0
  • 415935b Add yarn.lock.
  • 542a2a0 Migrate to lerna-changelog + add 1.10.0 to changelog.
  • a21fd1d Merge pull request #55 from SparshithNR/path-fix
  • f6d8238 Provide backward compatibility.
  • ab29353 Pass path as argument to livereload.js
  • 68c237e release v1.9.0 πŸŽ‰
  • 2e88996 Merge pull request #54 from SparshithNR/test-refactor
  • fcd41eb Refactoring and Tests

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of ember-cli-htmlbars-inline-precompile is breaking the build 🚨

The devDependency ember-cli-htmlbars-inline-precompile was updated from 3.0.0 to 3.0.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-cli-htmlbars-inline-precompile is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for Release 3.0.1

πŸ“ Documentation

🏠 Internal

  • #321 Re-roll yarn.lock to avoid errors with yarn 1.19.0 (@rwjblue)

Committers: 3

Commits

The new version differs by 22 commits.

  • 0a33678 Release 3.0.1
  • 2517d5d Merge pull request #320 from rwjblue/deprecate-and-noop
  • d3a4f4a Deprecate ember-cli-htmlbars-inline-precompiler.
  • a6f25ed Re-roll yarn.lock (#321)
  • 0eced26 Re-roll yarn.lock
  • ae928fe Bump ember-cli-babel from 7.11.0 to 7.11.1
  • 3b758a0 Bump ember-resolver from 5.2.1 to 5.3.0
  • c28a548 Fix import in README example (#305)
  • fc2d80b Fix import in README example
  • 3937089 Bump release-it from 12.4.0 to 12.4.1
  • 1307f86 Bump release-it from 12.3.6 to 12.4.0
  • 36d663e Bump eslint from 6.3.0 to 6.4.0
  • f897fb0 Bump babel-plugin-htmlbars-inline-precompile from 2.0.0 to 2.1.0
  • a66feba Merge pull request #299 from ember-cli/rwjblue-patch-1
  • 93f776b Remove problematic Chrome flags

There are 22 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Can't setup ember-model-validator

Hi,
I can't get the model inside the router,
I am getting an error:
TypeError: fakeModel is undefined
or
TypeError: fakeModel.validate is not a function

also I am using ember-mirage as a single mock server.

numericality validator assumes presence

If I put a numericality validator on one of my nullable number fields, validation will fail if input is blank. The validator should not assume the behavior of the presence validator; presence should be specified separately.

allow blank = true for numericality

numericality: {
onlyInteger: true,
allowBlank: true
}

Is there a reason why Ember.isBlank() is being used instead of Ember.isEmpty()?
For the above validation, x = ' ' validates as true, which is expected using isBlank. Coupled with an onlyInteger validation, this doesn't quite make sense.

Ember Data 2.1 compatibility with belongsTo?

Hey!

I'm working with ember-model-validator and EmberData 2.1 and I'm having an issue validating a belongsTo relationship. I'm using version 1.1.0 of ember-model-validator

I've create my model like the following

import DS from 'ember-data';
import Ember from 'ember';
import Validator from 'weldnote/mixins/model-validator';

const { computed, isEmpty, inject } = Ember;
const { belongsTo } = DS;

export default DS.Model.extend(Validator, {
  i18n: inject.service(),
  code: belongsTo('industry-code', { async: false }),

  validations: {
    code: {
      presence: true
    }
  }

});

When I call validate() the code is considered to be empty (but it's not).
I've managed to debug the issue to the following:

//model-validator.js
_validatePresence: function _validatePresence(property, validation) {
      var propertyValue = this.get(property);
      // If the property is an async relationship.
      if (this._modelRelations() && !Ember['default'].isBlank(this._modelRelations()[property])) {
        propertyValue = this.get(property + '.content'); // Here is the problem
      }
      if (Ember['default'].isBlank(propertyValue)) {
        this.set('isValidNow', false);
        this._addToErrors(property, validation.presence, Messages['default'].presenceMessage);
      }
    },

If I console.log propertyValue, right before the this.get(property + .content') I get the following
Class {store: Class, container: Container, _internalModel: ember$data$lib$system$model$internal$model$$InternalModel, isError: false, adapterError: (...)

But the this.get(property + '.content') returns undefined.... was it this way with older versions of Ember Data (I'm guessing that's my problem).

I've been dealing with this through custom validations, but it's kind of annoying to always do this:

validations: {
    code: {
      custom: {
        validation(key, value, model) {
          let id = model.get('code.id');
          return !isEmpty(id);
        }, message(key, value) {
          let translation = value.translate('edit-view.attributes.required');
          return translation;
        }
      }
    }

Thanks a lot for the project. It's been very helpful

An in-range update of sass is breaking the build 🚨

The devDependency sass was updated from 1.14.2 to 1.14.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

sass is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for Dart Sass 1.14.3

To install Dart Sass 1.14.3, download one of the packages above and add it to your PATH, or see the Sass website for full installation instructions.

Changes

  • Treat :before, :after, :first-line, and :first-letter as pseudo-elements for the purposes of @extend.

  • When running in compressed mode, remove spaces around combinators in complex selectors, so a selector like a > b is output as a>b.

  • Properly indicate the source span for errors involving binary operation expressions whose operands are parenthesized.

See the full changelog for changes in earlier releases.

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

ember model validator breaks on ember-data 1.0.0-beta.19.1

in store.recordWasInvalid(this, errors); throws an error Uncaught TypeError: internalModel.adapterDidInvalidate is not a function.

reading the source code of ember-data I found this

// ===== InternalModel
// FOR USE DURING COMMIT PROCESS
/**
  @method adapterDidInvalidate
  @private
*/
adapterDidInvalidate: function (errors) {
  var recordErrors = this.getErrors();
  ember$data$lib$system$model$internal$model$$forEach.call(Ember.keys(errors), function (key) {
    recordErrors.add(key, errors[key]);
  });
  this._saveWasRejected();
}
// ===== InternalModel

/**
  This method is called once the promise returned by an
  adapter's `createRecord`, `updateRecord` or `deleteRecord`
  is rejected with a `DS.InvalidError`.
   @method recordWasInvalid
  @private
  @param {InternalModel} internalModel
  @param {Object} errors
*/
recordWasInvalid: function (internalModel, errors) {
  internalModel.adapterDidInvalidate(errors);
}

I think you should not call that method manually, instead make something like this: https://github.com/dockyard/ember-validations/blob/master/addon/validators/local/inclusion.js#L23

Doesn't validate belongsTo async relation

I have the following model

import DS from 'ember-data';
import Validator from '../mixins/model-validator';

var attr = DS.attr;

export default DS.Model.extend(Validator, {
  plan: DS.belongsTo('plan', {async: true}),
  validations: {
    plan: {
      presence: {
        message: 'Please select a plan'
      }
    }
  }
});

Then when I'm trying to validate a model trying to test the behavior when the validation fail, the validation pass, but if I delete the {async: true} the validations doesn't pass (as expected)

An in-range update of ember-cli is breaking the build 🚨

The devDependency ember-cli was updated from 3.15.1 to 3.15.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-cli is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v3.15.2

Blueprint Changes

Changelog

Thank you to all who took the time to contribute!

Commits

The new version differs by 9 commits.

  • e17502b 3.15.2
  • 4f1a5bb Add v3.15.2 to CHANGELOG.md.
  • 9e904a9 Avoid errors when ui is not present and a warning will be emi… (#9014)
  • e164076 Supply a more universal .ui
  • 972b3a0 Allow failure of Node 8 CI jobs. (#9015)
  • c89428a Allow failure of Node 8 CI jobs.
  • dc95c25 fix named UMD imports (#8924)
  • bc6d511 allow importing named UMD files
  • 98d3928 remove amd-shim duplication

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of ember-cli-htmlbars is breaking the build 🚨

The devDependency ember-cli-htmlbars was updated from 3.0.0 to 3.0.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-cli-htmlbars is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add priority errors message

First, thanks for your library it help me a lot.

Second, is there a way to prioritize errors message. For example, i have a too short message and a required message to show.

I would like to show "Requiredt" when its empty, not both. And if it too short, only "Too short".

Thanks man !

An in-range update of ember-template-lint is breaking the build 🚨

The devDependency ember-template-lint was updated from 1.5.2 to 1.5.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-template-lint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for Release 1.5.3

πŸ› Bug Fix

  • #805 Update no-action-modifiers and no-element-event-actions rules to suggest using the on modifier (@bmish)
  • #803 Add 'octane' config to export list so it can be used in .template-lintrc.js (@pgengler)

Committers: 3

Commits

The new version differs by 11 commits.

  • e75fa8e Release 1.5.3
  • cf82a30 Merge pull request #805 from bmish/on-recommendation
  • 8266a43 fix: update no-action-modifiers and no-element-event-actions rules to suggest using the on modifier
  • 978df8d Add yarn lint script which calls yarn lint:js (#806)
  • 8575c86 build(deps-dev): bump eslint-config-prettier from 6.0.0 to 6.1.0
  • 9d86807 build(deps-dev): bump eslint from 6.1.0 to 6.2.0
  • 169cc09 Add yarn lint script which calls yarn lint:js.
  • 2e265db build(deps): bump @glimmer/compiler from 0.41.4 to 0.42.0 (#802)
  • fd7275a Add 'octane' config to export list so it can be found (#803)
  • 3ff1cfb Add 'octane' config to export list so it can be found (fixes #799)
  • 440ea99 build(deps): bump @glimmer/compiler from 0.41.4 to 0.42.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Missing `Acceptance` validator.

These values: '1', 1, and true should be the acceptable values. But the user can specify it as well with the accept option.

how can i add observer to validationErrors

I have a property observing model-validator mixin property validationErrors but this is not observing the changes done in model values which are already validated. So it needs an explicit call to validate() method to update the error values in the form. Please guide us how to handle this here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.