How to use ember-changeset-validations - 10 common examples

To help you get started, we’ve selected a few ember-changeset-validations 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 adfinis-sygroup / ember-validated-form / tests / dummy / app / validations / user.js View on Github external
// BEGIN-SNIPPET quickstart-validations.js
import {
  validatePresence,
  validateLength,
  validateInclusion
} from "ember-changeset-validations/validators";

export default {
  firstName: [validatePresence(true), validateLength({ min: 3, max: 40 })],
  lastName: [validatePresence(true), validateLength({ min: 3, max: 40 })],
  aboutMe: [validateLength({ allowBlank: true, max: 200 })],
  country: [validatePresence(true)],
  gender: [validatePresence(true)],
  terms: [
    validateInclusion({
      list: [true],
      message: "Please accept the terms and conditions!"
    })
  ],
  color: [validatePresence(true)]
};
// END-SNIPPET
github poteto / ember-changeset-validations / addon / validators / presence.js View on Github external
return true;
    }

    let result = validate('presence', value, options, null, key);

    if (typeof result === 'boolean' || typeof result === 'string') {
      return result;
    } else {
      // We flipped the meaning behind `present` and `blank` so switch the two
      if (result.type === 'present') {
        result.type = 'blank';
      } else if (result.type === 'blank') {
        result.type = 'present';
      }

      return buildMessage(key, result);
    }
  };
}
github NYCPlanning / labs-zap-search / app / validators / presence-unless-value.js View on Github external
}
    }

    const result = validate('presence', value, options, null, key);

    if (typeof result === 'boolean' || typeof result === 'string') {
      return result;
    }
    // We flipped the meaning behind `present` and `blank` so switch the two
    if (result.type === 'present') {
      result.type = 'blank';
    } else if (result.type === 'blank') {
      result.type = 'present';
    }

    return buildMessage(key, result);
  };
}
github poteto / ember-changeset-validations / addon / utils / get-messages.js View on Github external
export default function getMessages(moduleMap = requirejs.entries, useCache = true) {
  let messagesModule = defaultMessages;

  if (useCache && isPresent(cachedRef)) {
    return cachedRef;
  }

  let moduleKey = emberArray(keys(moduleMap))
    .find((key) => key === moduleName);

  if (isPresent(moduleKey)) {
    // Merge the user specified messages with the defaults
    messagesModule = withDefaults(requireModule(moduleKey).default, messagesModule);
  }

  cachedRef = messagesModule;
  return messagesModule;
}
github jbandura / ember-legit-forms / tests / dummy / app / controllers / changeset-form.js View on Github external
init() {
    this._super(...arguments);
    const user = this.get('user');
    this.changeset = new Changeset(user, lookupValidator(this.UserValidations), this.UserValidations);
  },
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 skaterdav85 / ember-changeset-conditional-validations / tests / dummy / app / validations / settings.js View on Github external
import { validatePresence, validateLength } from 'ember-changeset-validations/validators';
import validateSometimes from 'ember-changeset-conditional-validations/validators/sometimes';

export default {
  paymentMethod: validatePresence(true),
  creditCardNumber: validateSometimes([
    validatePresence(true),
    validateLength({ is: 16 })
  ], function() {
    return this.get('paymentMethod') === 'credit-card';
  })
};
github poteto / ember-changeset-validations / tests / dummy / app / components / foo-bar.js View on Github external
import Component from '@ember/component';
import { validatePresence, validateLength } from 'ember-changeset-validations/validators';

const rulez = {
  firstName: [
    validatePresence(true),
    validateLength({ min: 2 })
  ],
  lastName: [
    validatePresence(true),
    validateLength({ min: 2 })
  ]
};

const schema = {
  firstName: null,
  lastName: null
};

export default Component.extend({
  rulez,
  schema
});
github mirai-audio / ember-i18n-changeset-validations / tests / dummy / app / routes / application.js View on Github external
model() {
    let store = get(this, 'store');
    let media = store.createRecord('media', {
      title: 'a title',
      url: 'http'
    });
    let validatorFn = lookupValidator(MediaValidations);
    let changeset = new Changeset(media, validatorFn, MediaValidations);
    changeset.validate();
    return changeset;
  }
});
github puzzle / cryptopus / frontend / app / validations / file-entry.js View on Github external
import {
  validatePresence,
  validateLength
} from "ember-changeset-validations/validators";

export default {
  description: [validateLength({ max: 300 })],
  file: [validatePresence(true)]
};