meteor-autoformmeteor-collection2meteor-reactmeteor-1.4

Autoform with Meteor React and Simple-Schema


Is there any possibility to make meteor-autoform work with meteor-collection2-core and react-meteor?

MWE

Preferably I would like to have something like this.

./imports/api/Books.js

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
const Books = new Mongo.Collection("books");
Books.attachSchema(new SimpleSchema({
    title: {
        type: String,
        label: "Title",
        max: 200
    },
        author: {
        type: String,
        label: "Author"
    },
}));
if (Meteor.isServer) {
    Meteor.publish('allBooks', function () {
        return Books.find({}, );
    });
};
export default Books;

./imports/client/NewBooks.js

import React, { Component, PropTypes } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { quickForm } from 'meteor-autoform';
import Books from '../api/Books';
class NewBooks extends Component {
  constructor(props) {
    super(props)
    this.state = {}
  }

  render() {
    return (
      <div className="container">
        <quickForm
            collection={Books}
            id="insertBookForm"
            type="insert">
        </quickForm>
      </div>
    )
  }
};
export default createContainer(() => {
  Meteor.subscribe('allBooks');
  return {
    books: Books.find().fetch()
  }
}, NewBooks);

Solution

  • To my knowledge, Autoform depends heavily on Blaze, so, you could either use blaze autoform components in react (see here), or you can use a different library for this. I used this in a recent project: github.com/nicolaslopezj/simple-react-form. It's powerful, but much more 'hands-on' than the magical Autoform (you have to write your own form and field components).