How to use ember-validators - 10 common examples

To help you get started, we’ve selected a few ember-validators 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 poteto / ember-changeset-validations / addon / utils / messages.js View on Github external
import _Messages from 'ember-validators/messages';
import { assign } from '@ember/polyfills';
import { capitalize, dasherize } from '@ember/string';

const Messages = assign({}, _Messages);

export default assign(Messages, {
  // Blank and present are flipped in ember-validators. Need to flip them back here
  blank: _Messages.present,
  present: _Messages.blank,

  getDescriptionFor(key = '') {
    return capitalize(dasherize(key).split(/[_-]/g).join(' '));
  }
});
github poteto / ember-changeset-validations / addon / utils / messages.js View on Github external
import _Messages from 'ember-validators/messages';
import { assign } from '@ember/polyfills';
import { capitalize, dasherize } from '@ember/string';

const Messages = assign({}, _Messages);

export default assign(Messages, {
  // Blank and present are flipped in ember-validators. Need to flip them back here
  blank: _Messages.present,
  present: _Messages.blank,

  getDescriptionFor(key = '') {
    return capitalize(dasherize(key).split(/[_-]/g).join(' '));
  }
});
github NYCPlanning / labs-zap-search / app / validators / presence-unless-value.js View on Github external
return (key, value, _oldValue, changes, content) => {
    if (target && (changes[target] || (changes[target] === undefined && content[target]))) {
      if ((changes[target] === targetValue) || (changes[target] === undefined && (content[target] === targetValue))) {
        return true;
      }
    }

    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 / validators / presence.js View on Github external
return (key, value, _oldValue, changes, content) => {
    if (targets && !targets.some((target) => changes[target] || (changes[target] === undefined && content[target]))) {
      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 offirgolan / ember-validators / tests / helpers / process-result.js View on Github external
export default function processResult(result) {
  if (result && typeof result === 'object') {
    let { type, context, message } = result;

    if (message) {
      return message;
    }

    set(context, 'description', Messages.getDescriptionFor(undefined, context));
    return Messages.getMessageFor(type, context);
  }

  return result;
}
github offirgolan / ember-validators / tests / helpers / validator-context.js View on Github external
createErrorMessage(type, value, options) {
    set(options, 'description', Messages.getDescriptionFor(undefined, options));
    return Messages.getMessageFor(type, options);
  }
};
github offirgolan / ember-validators / tests / helpers / validator-context.js View on Github external
createErrorMessage(type, value, options) {
    set(options, 'description', Messages.getDescriptionFor(undefined, options));
    return Messages.getMessageFor(type, options);
  }
};
github offirgolan / ember-validators / tests / helpers / process-result.js View on Github external
export default function processResult(result) {
  if (result && typeof result === 'object') {
    let { type, context, message } = result;

    if (message) {
      return message;
    }

    set(context, 'description', Messages.getDescriptionFor(undefined, context));
    return Messages.getMessageFor(type, context);
  }

  return result;
}
github hummingbird-me / hummingbird-client / app / models / profile-link.js View on Github external
isURL: computed('url', function() {
    const url = get(this, 'url');
    return regularExpressions.url.test(url);
  }).readOnly()
});
github offirgolan / ember-validators / addon / format.js View on Github external
}

  if (type && !regex && regularExpressions[type]) {
    regex = regularExpressions[type];
  }

  if (type === 'email') {
    if (regex === regularExpressions.email) {
      regex = formatEmailRegex(options);
    }

    set(options, 'regex', regex);
  }

  if (!canInvoke(value, 'match') || (regex && isEmpty(value.match(regex)) !== inverse)) {
    return validationError(type || 'invalid', value, options);
  }

  return true;
}