How to use uniforms - 10 common examples

To help you get started, we’ve selected a few uniforms 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 vazco / uniforms / packages / uniforms / __tests__ / BaseField.tsx View on Github external
render() {
      return (
        <div>
          
          {this.props.children}
        </div>
      );
    }
  }

  const error1 = { details: [{ name: 'a' }, { name: 'i' }] };
  const error2 = { details: [{ name: 'b' }] };
  const model = { a: { b: { c: 'example' } } };
  const onChange = jest.fn();
  const randomId = randomIds();
  const state = {
    changed: false,
    changedMap: {},
    submitting: false,
    label: true,
    disabled: false,
    placeholder: true,
    showInlineError: true,
  };

  const schema = new SimpleSchemaBridge({
    getDefinition(name) {
      // Simulate SimpleSchema.
      name = name.replace(/\d+/g, '$');

      return {
github vazco / uniforms / packages / uniforms-unstyled / src / SelectField.tsx View on Github external
allowedValues,
  checkboxes,
  disabled,
  fieldType,
  id,
  inputRef,
  label,
  name,
  onChange,
  placeholder,
  required,
  transform,
  value,
  ...props
}) =&gt; (
  <div>
    {label &amp;&amp; <label>{label}</label>}

    {/* TODO: Better handling of these props. */}
    {checkboxes || fieldType === Array
      ? renderCheckboxes({
          allowedValues,
          disabled,
          id,
          name,
          onChange,
          transform,
          value,
          fieldType,
        })
      : renderSelect({
          allowedValues,</div>
github vazco / uniforms / docs / examples / CustomFields / SubmitField.js View on Github external
type="submit"
  /&gt;
);
SubmitField.contextTypes = BaseField.contextTypes;

// This field is a kind of a shortcut for few fields. You can also access all
// field props here, like value or onChange for some extra logic.
const Composite = () =&gt; (
  <section>
    
    
    
  </section>
);

const CompositeField = connectField(Composite);

export default function ExamplesSubmitField() {
  return (
     alert(JSON.stringify(model, null, 2))}
    &gt;
      
      <hr>
      
      <br>
      
    
  );
}
github focallocal / fl-maps / imports / client / utils / uniforms-custom / InputField.js View on Github external
const handleChange = (e, onChange, max, min) =&gt; {
  const { value, type } = e.target

  // Prevent numbers lower than the minimum
  if (type === 'number' &amp;&amp; value &lt; min) {
    return
  }

  onChange(value.substr(0, max))
}

Text.defaultProps = { type: 'text' }

export default connectField(Text)
github focallocal / fl-maps / imports / client / utils / uniforms-custom / AutoForm.js View on Github external
const Auto = parent =&gt; class extends AutoForm.Auto(parent) {
    static Auto = Auto;
    onChange (key, value) {
      // starting date should not be later than ending date
      if (key === 'when.endingDate' &amp;&amp; value &lt; this.getModel().when.startingDate) {
        super.onChange('when.startingDate', value)
      } else if (key === 'when.startingDate' &amp;&amp; value &gt; this.getModel().when.endingDate) {
        super.onChange('when.endingDate', value)
      }
      // pass on all changes to super
      super.onChange(key, value)
    }
}
github vazco / uniforms / packages / uniforms-bridge-simple-schema-2 / src / register.ts View on Github external
import SimpleSchema from 'simpl-schema';
import createSchemaBridge from 'uniforms/createSchemaBridge';
import filterDOMProps from 'uniforms/filterDOMProps';

import SimpleSchema2Bridge from './SimpleSchema2Bridge';

// Register bridge.
createSchemaBridge.register(SimpleSchema2Bridge);

// Register custom property.
SimpleSchema.extendOptions(['uniforms']);

// There's no possibility to retrieve them at runtime
filterDOMProps.register(
  'allowedValues',
  'autoValue',
  'blackbox',
  'custom',
  'decimal',
  'defaultValue',
  'exclusiveMax',
  'exclusiveMin',
  'label',
  'max',
  'maxCount',
  'min',
  'minCount',
  'optional',
  'regEx',
  'trim',
github vazco / uniforms / packages / uniforms-bridge-simple-schema / src / register.ts View on Github external
// Register custom property.
SimpleSchema.extendOptions({
  uniforms: Match.Optional(
    Match.OneOf(
      String,
      Function,
      Match.ObjectIncluding({
        component: Match.Optional(Match.OneOf(String, Function))
      })
    )
  )
});

// There's no possibility to retrieve them at runtime
filterDOMProps.register(
  'allowedValues',
  'autoValue',
  'blackbox',
  'custom',
  'decimal',
  'defaultValue',
  'exclusiveMax',
  'exclusiveMin',
  'label',
  'max',
  'maxCount',
  'min',
  'minCount',
  'optional',
  'regEx',
  'trim',
github vazco / uniforms / docs / examples / CustomFields / SwapField.js View on Github external
const SwapField = (
  { children, fieldA, fieldB },
  { uniforms: { model, onChange } }
) =&gt; (
  <span style="{{">
    {cloneElement(Children.only(children), {
      onClick() {
        const valueA = get(model, fieldA);
        const valueB = get(model, fieldB);
        onChange(fieldA, valueB);
        onChange(fieldB, valueA);
      }
    })}
  </span>
);
SwapField.contextTypes = BaseField.contextTypes;
// Usage.
export default function ExampleSwapField() {
  return (
    <section>
       alert(JSON.stringify(model, null, 2))}
      &gt;
        
        
          
        
        
        
      </section>
github vazco / uniforms / docs / examples / CustomFields / DisplayIfField.js View on Github external
import React, { Children } from 'react';
import BaseField from 'uniforms/BaseField';
import nothing from 'uniforms/nothing';

import {
  AutoForm,
  SubmitField,
  TextField
} from '../../../website/components/universal';
import schema from './DisplayIfFieldSchema';

// We have to ensure that there's only one child, because returning an array
// from a component is prohibited.
const DisplayIf = ({ children, condition }, { uniforms }) =&gt;
  condition(uniforms) ? Children.only(children) : nothing;
DisplayIf.contextTypes = BaseField.contextTypes;

export default function ExamplesDisplayIfField() {
  return (
     alert(JSON.stringify(model, null, 2))}
    &gt;
      

       context.model.fieldA}&gt;
        <section>
          

           context.model.fieldB}&gt;
            <span>Well done!</span>
          </section>
github vazco / uniforms / docs / examples / CustomFields / SubmitField.js View on Github external
// uniforms-unstyled.
const SubmitField = (
  props,
  {
    uniforms: {
      error,
      state: { disabled, submitting, validating }
    }
  }
) =&gt; (
  <input type="submit" disabled="{!!(error">
);
SubmitField.contextTypes = BaseField.contextTypes;

// This field is a kind of a shortcut for few fields. You can also access all
// field props here, like value or onChange for some extra logic.
const Composite = () =&gt; (
  <section>
    
    
    
  </section>
);

const CompositeField = connectField(Composite);

export default function ExamplesSubmitField() {
  return (