How to use @uform/validator - 10 common examples

To help you get started, we’ve selected a few @uform/validator 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 alibaba / uform / packages / react-schema-renderer / src / shared / schema.ts View on Github external
validator: value => {
          return value % this.multipleOf === 0
            ? ''
            : getMessage('schema.multipleOf')
        }
      })
github alibaba / uform / packages / react-schema-renderer / src / shared / schema.ts View on Github external
validator: value => {
          return Object.keys(value || {}).length >= this.minProperties
            ? ''
            : getMessage('schema.minProperties')
        }
      })
github alibaba / uform / packages / react-schema-renderer / src / shared / schema.ts View on Github external
validator: value => {
          return Object.keys(value || {}).length <= this.maxProperties
            ? ''
            : getMessage('schema.maxProperties')
        }
      })
github alibaba / uform / packages / react-schema-renderer / src / shared / schema.ts View on Github external
validator: value => {
          return value === this.const ? '' : getMessage('schema.const')
        }
      })
github alibaba / uform / packages / react-schema-renderer / src / shared / schema.ts View on Github external
validator: value => {
          value = toArr(value)
          return value.some((item: any, index: number) => {
            for (let start = index; start < value.length; start++) {
              if (isEqual(value[start], item)) {
                return false
              }
            }
          })
            ? getMessage('schema.uniqueItems')
            : ''
        }
      })
github alibaba / uform / packages / core / src / form.ts View on Github external
this.rafValidateId = raf(() => {
        if (this.destructed) {
          return resolve()
        }
        return runValidation(
          values || this.state.values,
          this.fields,
          forceUpdate
        )
          .then(response => {
            const lastValid = this.state.valid
            const newErrors = reduce(
              response,
              (buf, { name, errors }) => {
                if (!errors.length) {
                  return buf
                } else {
                  return buf.concat({ name, errors })
                }
              },
              []
github alibaba / uform / packages / core / src / index.ts View on Github external
)
    }
    if (isFormState(target)) {
      return state.hasChanged(path)
    } else if (isFieldState(target) || isVirtualFieldState(target)) {
      const node = graph.get(target.path)
      return node && node.hasChanged(path)
    } else {
      throw new Error(
        'Illegal parameter,You must pass the correct state object(FormState/FieldState/VirtualFieldState).'
      )
    }
  }

  const state = new FormState(options)
  const validator = new FormValidator({
    ...options,
    matchStrategy
  })
  const graph = new FormGraph({
    matchStrategy
  })
  const applyWithScheduler = scheduler(options.validateConcurrentTimeMS)
  const formApi = {
    submit,
    reset,
    hasChanged,
    clearErrors,
    validate,
    setFormState,
    getFormState,
    setFieldState,
github alibaba / uform / packages / core / src / index.ts View on Github external
submittingTask: undefined
  }
  heart.publish(LifeCycleTypes.ON_FORM_WILL_INIT, state)
  state.subscription = {
    notify: onFormChange
  }

  graph.appendNode('', state)
  state.setState((state: IFormState) => {
    state.initialized = true
  })
  graph.subscribe(onGraphChange)
  return formApi
}

export const registerValidationFormats = FormValidator.registerFormats

export const registerValidationRules = FormValidator.registerRules

export const registerValidationMTEngine = FormValidator.registerMTEngine

export {
  setValidationLanguage,
  setValidationLocale,
  FormPath,
  FormPathPattern,
  FormGraph
}

export default createForm
github alibaba / uform / packages / core / src / index.ts View on Github external
notify: onFormChange
  }

  graph.appendNode('', state)
  state.setState((state: IFormState) => {
    state.initialized = true
  })
  graph.subscribe(onGraphChange)
  return formApi
}

export const registerValidationFormats = FormValidator.registerFormats

export const registerValidationRules = FormValidator.registerRules

export const registerValidationMTEngine = FormValidator.registerMTEngine

export {
  setValidationLanguage,
  setValidationLocale,
  FormPath,
  FormPathPattern,
  FormGraph
}

export default createForm
github alibaba / uform / packages / core / src / index.ts View on Github external
heart.publish(LifeCycleTypes.ON_FORM_WILL_INIT, state)
  state.subscription = {
    notify: onFormChange
  }

  graph.appendNode('', state)
  state.setState((state: IFormState) => {
    state.initialized = true
  })
  graph.subscribe(onGraphChange)
  return formApi
}

export const registerValidationFormats = FormValidator.registerFormats

export const registerValidationRules = FormValidator.registerRules

export const registerValidationMTEngine = FormValidator.registerMTEngine

export {
  setValidationLanguage,
  setValidationLocale,
  FormPath,
  FormPathPattern,
  FormGraph
}

export default createForm