Copleykj:mesosphere examples ---> templates:forms examples?


#1

I’m looking at switching out autoform for mesosphere, but I’m having trouble finding a simple example. The readme has a bunch of configuration, and code snippets, but I am new to this, so I’m hoping someone has an example of using this package in meteor. I don’t know exactly what it provides… ie. form generation, validation, automatic saving / updating of values to mongo, etc… autoform had a good example to get started, but I can’t find anything for mesosphere.

in fact, mesosphere search on this forum returns 0 results, so I’m guessing it’s either extremely easy to use, or not many people are using it.

thanks in advance!


#2

Mesosphere really only handles validation. Some people really like that, especially those coming from a more standard web development background because its familiar.

I personally have moved into using collection2 with simple-schema for everything I develop. It has a great validation workflow with tons of other great features and allows me to create a level of security that permits doing all database operations on the client. For me, even as the author of Mesosphere, this is a no brainer.

If you really wish to switch, I’ll be more than happy to help you get started.


#3

I’m flexible, just looking for the best solution for my project where I will have a LOT of fields on a lot of forms (All types of controls too: select boxes filled from a database collection, radio buttons, conditional fields that only show when certain other fields are set to a certain value, date fields, numbers, text boxes, etc)… and I’ve run into some issues with autoform…SO… if you like the “collection 2 with simple schema” solution, I’d love a pointer to an example where you are using it to create a form for an update or insert into a mongo collection.

Also, I believe I’m already using simpleschema with autoform so I probably have a start.


#4

Sure. Say you have a user profile and you store them in a profiles collection.

First the schema

Profiles = new Mongo.Collection("profiles");

var profileSchema = new SimpleSchema({
    firstName:{
        type:String,
        label:"First Name"
    },
    lastName:{
        type:String,
        label:"Last Name",
    },
    about:{
        type:String,
        label:"About You",
        autoform:{
            atFieldInput:{
                type:"textarea"
            }
        }
    }
});

Profiles.attachSchema(profileSchema);

Then in your html you can use the quickForm template…

{{> quickForm collection="Profiles" doc=this id="updateProfileForm" type="update"}}

It can get much more complicated than this and you’ll probably want to spend a good amount of time reading the docs for collection2, simple-schema, and autoform. The amount of documentation is daunting at first but in the long run I think its worth the time and effort.


#5

Thanks, but I was thinking there might be an alternative to autoform, since I’m having troubles with it that have gone unanswered for 5 days…

I’m fine with creating my own fields, but I was looking for a pattern that takes advantage of other packages to provide nice validation, and provide the update and inserts, without having to resort to this kind of stuff:

    'submit #chartForm': function (e) {
    e.preventDefault();
    var dbid = this._id;

    var newDemographics = this.demographics;

    newDemographics.lastName = e.target.lastName.value;
    newDemographics.firstName = e.target.firstName.value;
    newDemographics.chartStatus = parseInt(e.target.chartStatus.value);

    var updateFields = {
      "demographics": newDemographics};
    Meteor.call('updateChart', dbid, updateFields);
  }


  updateChart: function (id, fields) {
    console.log('updating id: ' + id + ' Lastname:' + fields.demographics.lastName + " isSimulation: " + this.isSimulation);
    return Chart.update({_id: id}, {$set: fields}, function (error) {
      if (error) {
// display the error to the user
        console.log("error on update " + error.reason);
      } else {
        console.log("awesome, updated record " + id);
      }
    });
  },

#6

Did you already have a look at the templates:forms package? It tries to do much less than autoforms and focuses on providing just the core mechanisms for forms. The schema is also defined via the SimpleSchema package, using its really great validation mechanisms.

Please note that the package author is currently working on improving the documentation. There is a preview of the new docs available here.


#7

Thanks, I did have that one on my short list as well, along with mesosphere… too bad it doesn’t have a more unique name… it makes it quite hard to search the internet looking for people using it, talking about it, giving examples, etc… but I’ll definitely check out the new documentation! Will that documentation jive with the current release, or will I need to switch to that branch?


#8

From what I have seen, I think the 0.2.0 documentation is more or less also fully applicable to the current published version on atmosphere. - But maybe the package author (@jamz) could give a quick comment on any major deltas.


#9

spending a lot of time reading through examples and that documentation, and it’s still confusing. Does anyone have a fully standalone example that illustrates using the templates:forms package to create, and update documents in a mongo collection with validation?


#10

You can also use http://viewmodel.meteor.com/ to easily create your own templates specific to your needs. You’ll have to integrate SimpleSchema’s validation mechanism though.


#11

Thanks @yasinuslu that does look promising