How to use the uniforms/BaseField.contextTypes function in uniforms

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 / docs / examples / CustomFields / SwapField.js View on Github external
const SwapField = (
  { children, fieldA, fieldB },
  { uniforms: { model, onChange } }
) => (
  <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 (
github vazco / uniforms / packages / uniforms-unstyled / src / SubmitField.js View on Github external
import React from 'react';
import filterDOMProps from 'uniforms/filterDOMProps';

const SubmitField = (
  { disabled, inputRef, value, ...props },
  { uniforms: { error, state } }
) =&gt; (
  <input value="" type="submit" disabled="{disabled">
);
SubmitField.contextTypes = BaseField.contextTypes;

export default SubmitField;
github vazco / uniforms / packages / uniforms-semantic / src / SubmitField.js View on Github external
import filterDOMProps from 'uniforms/filterDOMProps';

const SubmitField = (
  { className, disabled, inputRef, value, ...props },
  { uniforms: { error, state } }
) =&gt; (
  <input value="" type="submit" disabled="{disabled">
);
SubmitField.contextTypes = BaseField.contextTypes;

export default SubmitField;
github vazco / uniforms / packages / uniforms-material / src / ErrorsField.js View on Github external
error={!!error}
      fullWidth={!!fullWidth}
      margin={margin}
      variant={variant}
    &gt;
      {!!children &amp;&amp; (
        {children}
      )}
      {schema.getErrorMessages(error).map((message, index) =&gt; (
        
          {message}
        
      ))}
    
  );
ErrorsField.contextTypes = BaseField.contextTypes;

ErrorsField.defaultProps = {
  fullWidth: true,
  margin: 'dense'
};

export default ErrorsField;
github vazco / uniforms / packages / uniforms-semantic / src / ErrorsField.js View on Github external
nothing
  ) : (
    <div>
      {children}

      <ul>
        {schema.getErrorMessages(error).map((message, index) =&gt; (
          <li>{message}</li>
        ))}
      </ul>
    </div>
  );
ErrorsField.contextTypes = BaseField.contextTypes;

export default ErrorsField;
github vazco / uniforms / packages / uniforms-unstyled / src / ErrorsField.js View on Github external
const ErrorsField = ({ children, ...props }, { uniforms: { error, schema } }) =&gt;
  !error &amp;&amp; !children ? (
    nothing
  ) : (
    <div>
      {children}

      <ul>
        {schema.getErrorMessages(error).map((message, index) =&gt; (
          <li>{message}</li>
        ))}
      </ul>
    </div>
  );
ErrorsField.contextTypes = BaseField.contextTypes;

export default ErrorsField;