Skip to content

Commit

Permalink
Fixed initial value (closes #58).
Browse files Browse the repository at this point in the history
  • Loading branch information
radekmie committed Jun 30, 2016
1 parent b855648 commit 232b30b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/uniforms/src/helpers/connectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function connectField (component, {
return;
}

if (props.value === undefined && !props.field.optional) {
if (props.value === undefined && props.required) {
props.onChange(props.initialValue);
}
}
Expand Down
14 changes: 13 additions & 1 deletion packages/uniforms/test/helpers/connectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ describe('connectField', () => {
getDefinition (name) {
return {
'field': {type: Object, label: 'Field'},
'field.subfield': {type: Number, label: 'Subfield'}
'field.subfield': {type: Number, label: 'Subfield'},
'another': {type: String, optional: true}
}[name];
},

Expand Down Expand Up @@ -142,6 +143,17 @@ describe('connectField', () => {

expect(onChange.called).to.be.false;
});

it('respects `required`', () => {
const Field = connectField(Test, {initialValue: true});

mount(
<Field name="another" />,
reactContext
);

expect(onChange.called).to.be.false;
});
});

context('when called with `mapProps`', () => {
Expand Down

0 comments on commit 232b30b

Please sign in to comment.