How to use the ember-cp-validations/validators/base.extend function in ember-cp-validations

To help you get started, we’ve selected a few ember-cp-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 offirgolan / ember-cp-validations / addon / validators / alias.js View on Github external
*
 *  ## Examples
 *
 *  ```javascript
 *  validator('alias', 'attribute')
 *  validator('alias', {
 *    alias: 'attribute',
 *    firstMessageOnly: true
 *  })
 *  ```
 *
 *  @class Alias
 *  @module Validators
 *  @extends Base
 */
const Alias = Base.extend({
  /**
   * Normalized options passed in.
   * ```js
   * validator('alias', 'attribute')
   * // Becomes
   * validator('alias', {
   *   alias: 'attribute'
   * })
   * ```
   *
   * @method buildOptions
   * @param  {Object}     options
   * @param  {Object}     defaultOptions
   * @param  {Object}     globalOptions
   * @return {Object}
   */
github jelhan / croodle / app / validators / iso8601.js View on Github external
import { isArray } from '@ember/array';
import { isEmpty } from '@ember/utils';
import { assert } from '@ember/debug';
import BaseValidator from 'ember-cp-validations/validators/base';
import moment from 'moment';

export default BaseValidator.extend({
  validate(value, options = {}) {
    assert(
      'options.validFormats must not be set or an array of momentJS format strings',
      isEmpty(options.validFormats) || isArray(options.validFormats)
    );

    let valid;
    const validFormats = isEmpty(options.validFormats) ? ['YYYY-MM-DDTHH:mm:ss.SSSZ'] : options.validFormats;

    if (
      options.active === false ||
      (typeof options.active === 'function' && options.active() === false)
    ) {
      return true;
    }
github jelhan / croodle / app / validators / time.js View on Github external
import { isEmpty } from '@ember/utils';
import BaseValidator from 'ember-cp-validations/validators/base';
import moment from 'moment';

export default BaseValidator.extend({
  validate(value, options) {
    let valid;

    if (typeof options !== 'object') {
      options = {};
    }

    options.value = value;

    if (options.allowEmpty && isEmpty(value)) {
      return true;
    }

    if (!isEmpty(value) && typeof value.trim === 'function') {
      value = value.trim();
    }
github offirgolan / ember-cp-validations / addon / validators / belongs-to.js View on Github external
*    }
 *  });
 *  ```
 *
 *  From our `user` model, we can now check any validation property on the `user-details` model.
 *
 *  ```javascript
 *  get(model, 'validations.attrs.details.isValid')
 *  get(model, 'validations.attrs.details.messages')
 *  ```
 *
 *  @class Belongs To
 *  @module Validators
 *  @extends Base
 */
const BelongsTo = Base.extend({
  validate(value, ...args) {
    if (value) {
      if (isPromise(value)) {
        return value.then(model => this.validate(model, ...args));
      }

      return get(value, 'validations');
    }

    return true;
  }
});

BelongsTo.reopenClass({
  getDependentsFor(attribute) {
    return [
github offirgolan / ember-cp-validations / addon / -private / ember-validator.js View on Github external
import Base from 'ember-cp-validations/validators/base';
import { validate as _validate } from 'ember-validators';

export default Base.extend({
  validate() {
    let result = _validate(this.get('_evType'), ...arguments);

    if (result && typeof result === 'object') {
      return result.message
        ? result.message
        : this.createErrorMessage(result.type, result.value, result.context);
    }

    return result;
  }
});
github CenterForOpenScience / ember-osf-web / app / validators / mismatch.ts View on Github external
import { assert } from '@ember/debug';
import { get } from '@ember/object';
import { isEmpty, isEqual, isPresent } from '@ember/utils';
import BaseValidator from 'ember-cp-validations/validators/base';
import DS from 'ember-data';

interface Options {
    allowBlank: boolean;
    on: string;
}

const Mismatch = BaseValidator.extend({
    validate(value: string, options: Options, model: DS.Model, attribute: string): string | true {
        const on: any = get(options, 'on');
        const allowBlank: boolean = get(options, 'allowBlank');

        assert(`[validator:mismatch] [${attribute}] option 'on' is required`, isPresent(on));

        if (allowBlank && isEmpty(value)) {
            return true;
        }

        if (isEqual(value, get(model, on))) {
            return this.createErrorMessage('mismatch', value, options);
        }

        return true;
    },
github apache / ambari / contrib / views / wfmanager / src / main / resources / ui / app / validators / operand-length.js View on Github external
*    The ASF licenses this file to You under the Apache License, Version 2.0
*    (the "License"); you may not use this file except in compliance with
*    the License.  You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*/

import BaseValidator from 'ember-cp-validations/validators/base';

const OperandLength = BaseValidator.extend({
  validate(value, options, model, attribute) {
    if (options.min && value && value.length >= options.min) {
        return true;
    }else{
      if(options.message){
        return options.message;
      }
      return "At least two inputs are required";
    }
  }
});

OperandLength.reopenClass({
  /**
   * Define attribute specific dependent keys for your validator
   *
github apache / ambari / contrib / views / wfmanager / src / main / resources / ui / app / validators / workflow-dag.js View on Github external
*    this work for additional information regarding copyright ownership.
*    The ASF licenses this file to You under the Apache License, Version 2.0
*    (the "License"); you may not use this file except in compliance with
*    the License.  You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*/
import BaseValidator from 'ember-cp-validations/validators/base';

const WorkflowDag = BaseValidator.extend({
  validate(value, options, model, attribute) {
    if (model.get('dataNodes') && model.get('dataNodes').length) {
      if(!model.get('flowRenderer').isWorkflowValid()){
        return "Invalid workflow structure. There is no flow to end node.";
      }
    }
  }
});

WorkflowDag.reopenClass({
  /**
   * Define attribute specific dependent keys for your validator
   *
   * @param {String}  attribute   The attribute being evaluated
   * @param {Unknown} options     Options passed into your validator
   * @return {Array}
github jelhan / croodle / app / validators / valid-collection.js View on Github external
import BaseValidator from 'ember-cp-validations/validators/base';

export default BaseValidator.extend({
  validate(value, options) {
    if (options.active === false) {
      return true;
    }

    const valid = value.every((element) => {
      return element.get('validations.isValid');
    });

    if (valid) {
      return true;
    } else {
      return this.createErrorMessage('validCollection', options, value);
    }
  }
});
github ilios / frontend / app / validators / html-presence.js View on Github external
import { isEmpty } from '@ember/utils';
import BaseValidator from 'ember-cp-validations/validators/base';

export default BaseValidator.extend({
  validate(value, options) {
    let text = value || '';
    let noTagsText = text.replace(/(<([^>]+)>)/ig,"");
    let strippedText = noTagsText.replace(/ /ig,"").replace(/\s/g, "");
    if (isEmpty(strippedText)) {
      return this.createErrorMessage('blank', value, options);
    }

    return true;
  }
});