Edit In Place
Small and Flexible edit in place components for meteor.
meteor add robincwillis:edit-in-place
What it do
Edit in place is a Meteor package that provides UI elements to easily edit values in line. It can be used both reactively or not. It does not automatically insert, update or delete documents but rather triggers events and sends changes made which then you can listen to and do what you want with the changes, ie call a Meteor method, run some validation, whatever.
Getting Started
The easiest way to get started is to clone this repository and run the example code
$ git clone git@github.com:robincwillis/meteor-edit-in-place.git
$ cd meteor/edit-in-place/example
$ meteor
How It Works
Partials
To use Edit in Place simply include one of the partials included with the package. The following input types are available.
A basic text input
{{> eipInput
collection="Books"
item=book
attribute="title"
}}
A select input
{{> eipSelect
collection="Colors"
item=color
attribute="value"
type="Number"
options=colorOptions
}}
A list of text inputs
{{> eipList
collection="Books"
list=books
attribute="title"
}}
Parameters
At a minimum each partial requires the following parameters
collection
:String
The collection which this document belongs to.item/list
:Object
orArray
The document or documents which are being .modifiedattribute
:String
The key for the attribute that is being modified.options
: (only foreipSelect
) Select inputs need a list of options for the select element, this should be an array of objects in this format.
[
{label : "A", value : 1 },
{label : "B", value : 2 },
{label : "C", value : 3 }
]
Optional
reactive
:Boolean
By default edit in place will not make any changes to values represented in the DOM. Making these changes is not the Meteor way of doing things, instead it will return changes back to you, so that you can update your collections and documents accordingly, those reactive changes will feedback into the Edit in Place partials. However if you don't want to do this you can set this parameter tofalse
.value
: You can override the initial value shown in Edit in Place partial by setting this parameter.type
:"String"
,"Number"
,"Date"
Specify how the value should be formated when returned back from Edit in Place.
Events
Edit in place will trigger a number of custom events on changes to each partial, the events are
onEipTrigger
: When someone begins editingonEipSave
: When someone ends editingonEipBlur
: When the input field in the partial loses focusonEipChange
: When the value of a select input has been changedonEipDelete
: When someone clicks the delete icon on a list item
You can listen for in your Meteor template like this.
Template.hello.events({
'onEipTrigger' : function(e, t){
console.log(this); // {collection: Mongo.Collection, item: Object, attribute: "title", value: "robin willis"}
},
'onEipSave' : function(e, t){
console.log(this); // {collection: Mongo.Collection, item: Object, attribute: "title", value: "robin willis"}
var obj = {};
obj[this.attribute] = this.value;
this.collection.update(this.item._id, obj);
},
'onEipBlur' : function(e, t){
console.log(this); // {collection: Mongo.Collection, item: Object, attribute: "title", value: "robin willis"}
},
'onEipChange' : function(e, t){
console.log(this); // {collection: Mongo.Collection, item: Object, attribute: "title", value: "robin willis"}
},
'onEipDelete' : function(e, t){
console.log(this); // {collection: Mongo.Collection, item: Object, attribute: "title", value: "robin willis"}
this.collection.remove(this.item);
}
});
Custom Events
You can override any of the events triggered by specifying custom events as parameters in the template. This lets you listen for events on individual inputs rather than all inputs.
customTrigger
:"String"
customSave
:"String"
customBlur
:"String"
customChange
:"String"
customDelete
:"String"