Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: partial model validation #14

Open
basz opened this issue Jan 28, 2018 · 0 comments
Open

RFC: partial model validation #14

basz opened this issue Jan 28, 2018 · 0 comments

Comments

@basz
Copy link

basz commented Jan 28, 2018

To be able to partially validate models, I have added a file with this content - which overrides the BsForm provided by this package.

Setting `{{bs-form validationOptions=(hash on=(array 'fieldPath') excludes=(array 'otherPath')) enables this.

I'm not sure about model.set('validations.errors', validations.get('errors')); but model.get('isTruelyValid') seems to work.

import ObjectProxy from '@ember/object/proxy';
import { Promise as EmberPromise } from 'rsvp';
import BsForm from 'ember-bootstrap/components/bs-form';

export default BsForm.extend({
  validationOptions: {},
  validate(model) {
    return new EmberPromise((resolve, reject) => {
      let m = model;

      if (model instanceof ObjectProxy) {
        m = model.get('content');
      }

      m.validate(this.get('validationOptions')).then(
        validations => {
          model.set('validations.errors', validations.get('errors'));
          model.get('validations.isTruelyValid') ? resolve() : reject();
        },
        error => {
          reject();
        }
      );
    });
  }
});

Thoughts? think it might be good to create a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant