uniforms: SelectField value not being set in submission document

I use a SelectField like this:

<AutoForm
    schema={Collection1.schema}
    onSubmit={doc => console.log(doc)}
>
    <SelectField name="field1" onChange={(value) => { this.setState({ stateVar: value }) }} value={this.state.stateVar} />

this.state was initialized in the constructor:

  constructor(props) {
    super(props);
    this.state = {
      stateVar: "N",
    };
  }

If field1 is not set as optional in the schema, then validation fails with the “required” error message. if optional: true is set for field1, the console.log shows no field1 in the submission document.

How can this problem be fixed?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (15 by maintainers)

Most upvoted comments

I’ve just made a new minimal app to reproduce the error:

import React, { Component } from 'react';

class App extends Component {
    handleSubmit(doc) {
        console.log(doc)
    }

    render() {
        import { AutoForm, SelectField, SubmitField, ErrorsField } from 'uniforms-bootstrap4';

        const optionsArray = [{ label: "label 1", value: "value 1" }, { label: "label 2", value: "value 2" }]

        return (
          <div className="container">
          <AutoForm
                schema={itemsSchema}
                onSubmit={doc => this.handleSubmit(doc)}
            >
                <SelectField name="itemId" options={optionsArray} />

                <ErrorsField />

                <SubmitField />
            </AutoForm>
            </div>
        )
    }
}


import { createContainer } from 'meteor/react-meteor-data';
export default createContainer((props) => {
    return {}
}, App)


import SimpleSchema from 'simpl-schema'
const itemsSchema = new SimpleSchema({
    itemId: {
        type: String,
    },
});

Run the app and click on Submit. It will say Item ID is required even though “label 1” is clearly selected.

Please reopen this issue, as it was closed prematurely.