Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))}
>
</section>
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 }) =>
condition(uniforms) ? Children.only(children) : nothing;
DisplayIf.contextTypes = BaseField.contextTypes;
export default function ExamplesDisplayIfField() {
return (
alert(JSON.stringify(model, null, 2))}
>
context.model.fieldA}>
<section>
context.model.fieldB}>
<span>Well done!</span>
</section>
// uniforms-unstyled.
const SubmitField = (
props,
{
uniforms: {
error,
state: { disabled, submitting, validating }
}
}
) => (
<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 = () => (
<section>
</section>
);
const CompositeField = connectField(Composite);
export default function ExamplesSubmitField() {
return (
import React from 'react';
import filterDOMProps from 'uniforms/filterDOMProps';
const SubmitField = (
{ disabled, inputRef, value, ...props },
{ uniforms: { error, state } }
) => (
<input value="" type="submit" disabled="{disabled">
);
SubmitField.contextTypes = BaseField.contextTypes;
export default SubmitField;
import filterDOMProps from 'uniforms/filterDOMProps';
const SubmitField = (
{ className, disabled, inputRef, value, ...props },
{ uniforms: { error, state } }
) => (
<input value="" type="submit" disabled="{disabled">
);
SubmitField.contextTypes = BaseField.contextTypes;
export default SubmitField;
error={!!error}
fullWidth={!!fullWidth}
margin={margin}
variant={variant}
>
{!!children && (
{children}
)}
{schema.getErrorMessages(error).map((message, index) => (
{message}
))}
);
ErrorsField.contextTypes = BaseField.contextTypes;
ErrorsField.defaultProps = {
fullWidth: true,
margin: 'dense'
};
export default ErrorsField;
nothing
) : (
<div>
{children}
<ul>
{schema.getErrorMessages(error).map((message, index) => (
<li>{message}</li>
))}
</ul>
</div>
);
ErrorsField.contextTypes = BaseField.contextTypes;
export default ErrorsField;
const ErrorsField = ({ children, ...props }, { uniforms: { error, schema } }) =>
!error && !children ? (
nothing
) : (
<div>
{children}
<ul>
{schema.getErrorMessages(error).map((message, index) => (
<li>{message}</li>
))}
</ul>
</div>
);
ErrorsField.contextTypes = BaseField.contextTypes;
export default ErrorsField;