How to use revalidator - 10 common examples

To help you get started, we’ve selected a few revalidator 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 esnet / react-dynamic-forms / packages / react-dynamic-forms / src / components / TextEdit.js View on Github external
// If the user has a field blank then that is never an error. Likewise if the field
        // is disabled then that is never an error.
        if (this.isEmpty(value) || this.props.disabled) {
            return result;
        }

        // Validate the value with Revalidator, given the rules in this.props.rules
        let obj = {};
        obj[this.props.name] = value;

        let properties = {};
        properties[this.props.name] = this.props.validation;

        const rules = this.props.validation ? { properties } : null;
        if (obj && rules) {
            const validation = validate(obj, rules, { cast: true });
            const name = this.props.name || "Value";

            let msg;
            if (!validation.valid) {
                msg = `${name} ${validation.errors[0].message}`;
                result.validationError = true;
                result.validationErrorMessage = msg;
            }
        }
        return result;
    }
github esnet / react-dynamic-forms / src / forms / components / TextEdit.js View on Github external
// If the user has a field blank then that is never an error. Likewise if the field
        // is disabled then that is never an error.
        if (this.isEmpty(value) || this.props.disabled) {
            return result;
        }

        // Validate the value with Revalidator, given the rules in this.props.rules
        let obj = {};
        obj[this.props.name] = value;

        let properties = {};
        properties[this.props.name] = this.props.validation;

        const rules = this.props.validation ? { properties } : null;
        if (obj && rules) {
            const validation = validate(obj, rules, { cast: true });
            const name = this.props.name || "Value";

            let msg;
            if (!validation.valid) {
                msg = `${name} ${validation.errors[0].message}`;
                result.validationError = true;
                result.validationErrorMessage = msg;
            }
        }
        return result;
    }
github esnet / react-dynamic-forms / packages / react-dynamic-forms / src / components / TextArea.js View on Github external
// If the user has a field blank then that is never an error
        // Likewise if this item is disabled it can't be called an error
        if (this.isEmpty(value) || this.props.disabled) {
            return result;
        }

        // Validate the value with Revalidator, given the rules in this.props.rules
        let obj = {};
        obj[this.props.name] = value;

        let properties = {};
        properties[this.props.name] = this.props.rules;

        const rules = this.props.rules ? { properties } : null;
        if (obj && rules) {
            const validation = validate(obj, rules, { cast: true });
            const name = this.props.name || "Value";

            let msg;
            if (!validation.valid) {
                msg = `${name} ${validation.errors[0].message}`;
                result.validationError = true;
                result.validationErrorMessage = msg;
            }
        }
        return result;
    }
github nebrius / aquarium-control / controller / src / messaging.ts View on Github external
twin.on('properties.desired', (desiredChange) => {

        // Validate the incoming data and see if there are any changes, if so save it
        const newConfig: IConfig = JSON.parse(desiredChange.config);
        if (validate(newConfig, configValidationSchema).valid && !equals(state.getConfig(), newConfig)) {
          state.setConfig(newConfig);
        }

        // Check if we don't need to acknowledge receipt of the changes and skip if so
        if (twin.properties.desired.$version === twin.properties.reported.$version) {
          return;
        }
      });
github sachabarber / MadCapIdea / PlayBackEndApi / FrontEndWebSite / src / PassengerRegistration.tsx View on Github external
validateForm = (values) => {
        let res = revalidator.validate(values, schema);

        // If the values passed validation, we return true
        if (res.valid) {
            return true;
        }

        // Otherwise we should return an object containing errors
        // e.g. { email: true, password: true }
        return res.errors.reduce((errors, error) => {
            // Set each property to either true or
            // a string error description
            errors[error.property] = true;

            return errors;
        }, {});
    }
github NextCenturyCorporation / EVEREST / services / database / assertion.js View on Github external
me.validateAssertion = function(data, valCallback) {
		// is the JSON semantically valid for the assertion object?
		var valid = revalidator.validate(data, validationModel);
		if (valid.valid) {
			// does the assertion object comply with business validation logic
			bvalidator.validate(data, function(valid) {
				valCallback(valid);
			});
		} else {
			valCallback(valid);
		}
	};
github nebrius / aquarium-control / server / src / endpoints.ts View on Github external
app.post('/api/config', async (req, res) => {
    if (!validate(req.body, configValidationSchema).valid) {
      res.sendStatus(400);
      return;
    }
    try {
      await updateConfig(req.body as IConfig);
      await updateSchedule();
      res.send({ result: 'ok' });
    } catch (e) {
      console.error(`[Endpoint]: ${e}`);
      res.sendStatus(500);
    }
  });
github OpenNetworkingFoundation / EagleUmlCommon / UmlPruningRefactoringTools / P&R Tool / node_modules / prompt / lib / prompt.js View on Github external
function convert(schema) {
  var newProps = Object.keys(validate.messages),
      newSchema = false,
      key;

  newProps = newProps.concat(['description', 'dependencies']);

  for (key in schema) {
    if (newProps.indexOf(key) > 0) {
      newSchema = true;
      break;
    }
  }

  if (!newSchema || schema.validator || schema.warning || typeof schema.empty !== 'undefined') {
    schema.description = schema.message;
    schema.message = schema.warning;
github AnyMesh / anyMesh-Node / node_modules / prompt / lib / prompt.js View on Github external
function convert(schema) {
  var newProps = Object.keys(validate.messages),
      newSchema = false,
      key;

  newProps = newProps.concat(['description', 'dependencies']);

  for (key in schema) {
    if (newProps.indexOf(key) > 0) {
      newSchema = true;
      break;
    }
  }

  if (!newSchema || schema.validator || schema.warning || typeof schema.empty !== 'undefined') {
    schema.description = schema.message;
    schema.message = schema.warning;

revalidator

A cross-browser / node.js validator powered by JSON Schema

Apache-2.0
Latest version published 10 years ago

Package Health Score

59 / 100
Full package analysis