How to use the ember-changeset function in ember-changeset

To help you get started, we’ve selected a few ember-changeset examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CenterForOpenScience / ember-osf-web / lib / osf-components / addon / components / validated-model-form / component.ts View on Github external
useOptions = options;
        }
        const validationMap = model.validations.validatableAttributes.reduce(
            (o: any, attr: string) => {
                o[attr] = true; // eslint-disable-line no-param-reassign
                return o;
            },
            {},
        );

        const validateFn: ValidatorFunc = async params => {
            const { validations } = await model.validateAttribute(params.key, params.newValue);
            return validations.isValid ? true : validations.message;
        };

        return new Changeset(model, validateFn, validationMap, useOptions) as ChangesetDef;
    }
github kaliber5 / ember-bootstrap-changeset-validations / tests / dummy / app / controllers / application.js View on Github external
init() {
    this._super(...arguments);
    this.changeset = new Changeset(model, lookupValidator(validation), validation);
  },
github offirgolan / ember-changeset-cp-validations / addon / index.js View on Github external
export default function createChangeset(model, fn) {
  let { validateFn, validationMap } = buildChangeset(model);
  let _fn;

  if (fn && typeof fn === 'function') {
    _fn = function() {
      return fn(...arguments, validateFn);
    };
  }

  return new Changeset(model, _fn || validateFn, validationMap);
}
github puzzle / cryptopus / frontend / app / components / file-entry / form.js View on Github external
constructor() {
    super(...arguments);

    this.record = this.args.fileEntry || this.store.createRecord("file-entry");

    this.changeset = new Changeset(
      this.record,
      lookupValidator(FileEntryValidations),
      FileEntryValidations
    );

    this.changeset.account = this.args.account;

    var token = ENV.CSRFToken;
    this.changeset.csrfToken = token;
  }
github scrapinghub / portia / portiaui / app / components / fragment-options.js View on Github external
changeset: computed('fragment.type', function() {
        const validations = VALIDATIONS[this.get('fragment.type')];
        return new Changeset(
           this.get('fragment'),
           lookupValidator(validations),
           validations
        );
    }),
github poteto / ember-changeset / addon / helpers / changeset.ts View on Github external
export function changeset(
  [obj, validations]: [object | Promise, ValidatorFunc],
  options: Config = {}
): Changeset | Promise {
  if (isChangeset(obj)) {
    return obj;
  }

  if (isPromise(obj)) {
    return Promise.resolve(obj).then((resolved: any) => new Changeset(resolved, validations, {}, options));
  }

  return new Changeset(obj, validations, {}, options);
}
github NYCPlanning / labs-zap-search / app / controllers / my-projects / assignment / recommendations / add.js View on Github external
    return this.dispositions.map(disposition => new Changeset(disposition, lookupValidator(dispositionValidations), dispositionValidations));
  }
github puzzle / cryptopus / frontend / app / components / folder / form.js View on Github external
constructor() {
    super(...arguments);

    this.record = this.args.folder || this.store.createRecord("folder");

    this.isNewRecord = this.record.isNew;

    this.changeset = new Changeset(
      this.record,
      lookupValidator(FolderValidations),
      FolderValidations
    );

    if (this.isNewRecord && this.navService.selectedTeam)
      this.changeset.team = this.navService.selectedTeam;

    if (this.isNewRecord && isPresent(this.args.team)) {
      this.changeset.team = this.args.team;
    }

    this.store.findAll("team").then((teams) => {
      this.assignableTeams = teams;
    });
  }