How to use the vuelidate.withParams function in vuelidate

To help you get started, we’ve selected a few vuelidate 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 mokkabonna / vue-vuelidate-jsonschema / src / validators / oneOf.js View on Github external
module.exports = function oneOfValidator(propertySchema, schemas, getPropertyValidationRules) {
  return vuelidate.withParams({
    type: 'schemaOneOf',
    schemas: schemas,
    schema: propertySchema
  }, function(val) {
    if (!noParamsRequired(val)) {
      return true
    }

    // ignore type errors, the type validator handles that
    if (!typeValidator(propertySchema, propertySchema.type)(val)) {
      return true
    }

    return schemas.reduce(function(matching, schema) {
      if (matching > 1) return 2
      if (validate(getPropertyValidationRules(schema), val)) return matching + 1
github mokkabonna / vue-vuelidate-jsonschema / src / validators / allOf.js View on Github external
module.exports = function allOfValidator(propertySchema, schemas, getPropertyValidationRules) {
  return vuelidate.withParams({
    type: 'schemaAllOf',
    schemas: schemas,
    schema: propertySchema
  }, function(val) {
    if (!noParamsRequired(val)) {
      return true
    }

    // ignore type errors, the type validator handles that
    if (!typeValidator(propertySchema, propertySchema.type)(val)) {
      return true
    }

    return schemas.every(function(itemSchema) {
      return validate(getPropertyValidationRules(itemSchema), val)
    })
github mokkabonna / vue-vuelidate-jsonschema / src / validators / not.js View on Github external
module.exports = function notValidator(propertySchema, notSchema, getPropertyValidationRules) {
  return vuelidate.withParams({
    type: 'schemaNot',
    not: notSchema,
    schema: propertySchema
  }, function(val) {
    if (!noParamsRequired(val)) {
      return true
    }

    // ignore type errors, the type validator handles that
    if (!typeValidator(propertySchema, propertySchema.type)(val)) {
      return true
    }

    return !validate(getPropertyValidationRules(notSchema), val)
  })
}
github mokkabonna / vue-vuelidate-jsonschema / src / validators / patternProperties.js View on Github external
module.exports = function patternPropertiesValidator(propertySchema, patternProperties, getPropertyValidationRules) {
  return vuelidate.withParams({
    type: 'schemaPatternProperties',
    patternProperties: patternProperties,
    schema: propertySchema
  }, function(object) {
    if (!isPlainObject(object)) return true

    if (propertySchema.additionalProperties !== undefined &&
      !isPlainObject(propertySchema.additionalProperties) &&
      propertySchema.additionalProperties !== true
    ) {
      var allowedKeys = Object.keys(patternProperties).map(function(key) {
        return new RegExp(key)
      })

      var allKeysAreValid = Object.keys(object).every(function(key) {
        // we have key, therefore it is valid
github mokkabonna / vue-vuelidate-jsonschema / src / validators / minLength.js View on Github external
module.exports = function minLengthValidator(propertySchema, min) {
  return vuelidate.withParams({
    type: 'schemaMinLength',
    schema: propertySchema,
    min: min
  }, function(val) {
    if (!isString(val)) return true
    return val.length >= min
  })
}
github mokkabonna / vue-vuelidate-jsonschema / src / validators / maxLength.js View on Github external
module.exports = function maxLengthValidator(propertySchema, max) {
  return vuelidate.withParams({
    type: 'schemaMaxLength',
    schema: propertySchema,
    max: max
  }, function(val) {
    if (!isString(val)) return true
    return val.length <= max
  })
}
github mokkabonna / vue-vuelidate-jsonschema / src / validators / enum.js View on Github external
module.exports = function oneOfValidator(propertySchema, choices) {
  return vuelidate.withParams({
    type: 'schemaEnum',
    choices: choices,
    schema: propertySchema
  }, function(val) {
    if (!noParamsRequired(val)) return true
    return choices.some(function(choice) {
      return isEqual(val, choice)
    })
  })
}
github mokkabonna / vue-vuelidate-jsonschema / src / validators / propertyNames.js View on Github external
module.exports = function propertyNamesValidator(propertySchema, propertyNames, getPropertyValidationRules) {
  return vuelidate.withParams({
    type: 'schemaPropertyNames',
    propertyNames: propertyNames,
    schema: propertySchema
  }, function(obj) {
    if (!isPlainObject(obj)) return true
    var properties = Object.keys(obj)
    var validatorGroup = getPropertyValidationRules(propertyNames)

    return properties.every(function(property) {
      return validate(validatorGroup, property)
    })
  })
}
github mokkabonna / vue-vuelidate-jsonschema / src / validators / additionalProperties.js View on Github external
module.exports = function additionalPropertiesValidator(propertySchema, additionalProperties, getPropertyValidationRules) {
  return vuelidate.withParams({
    type: 'schemaAdditionalProperties',
    additionalProperties: additionalProperties,
    schema: propertySchema
  }, function(object) {
    if (!object || !isPlainObject(object)) return true
    var keys = Object.keys(object)
    var properties = Object.keys(propertySchema.properties || {})
    var additionalKeys
    if (additionalProperties === true || additionalProperties === undefined) {
      return true
    } else {
      if (!propertySchema.patternProperties) {
        if (additionalProperties === false) {
          return keys.every(function(key) {
            return properties.indexOf(key) !== -1
          })
github mokkabonna / vue-vuelidate-jsonschema / src / validators / required.js View on Github external
module.exports = function requiredValidator(propertySchema, isAttached) {
  return vuelidate.withParams({
    type: 'schemaRequired',
    schema: propertySchema
  }, function(val, parent) {
    if (!isPlainObject(parent) && isAttached) {
      return true
    } else {
      return noParamsRequired(val)
    }
  })
}