meteor-autocomplete icon indicating copy to clipboard operation
meteor-autocomplete copied to clipboard

If no match found, add a button to create new item in collection

Open taxigy opened this issue 10 years ago • 2 comments

Let's say I have a simple collection:

Contact = new SimpleSchema({
    name: {
        type: String,
        unique: true
    }
});
Contacts = new Mongo.Collection('contacts');

And I want to let app users add new items into this collection either in insert or update AutoForm. In current state, it seems not possible, and values that don't match are just ignored.

taxigy avatar Sep 20 '15 21:09 taxigy

Yep, this is already mentioned in #95 and also I'd like to add AutoForm support at some point (#9, #91).

Maybe you can write a PR?

mizzao avatar Sep 23 '15 20:09 mizzao

I think we should keep this package lightweight...

Here what i did if you need to create new item if no-match found:

on submit event
var i = t.find('input').value   // retrieve input value from autocomplete input box
console.log(i); // return user's input value
var c = C.find({}, {    // fetch array of collection
    fields: {title:1, src:1, sC:1, _id:0},
    transform: null
}).fetch();
console.log(c);
var a = _.filter(c, _.matches({'title':i}));    // filter c to only retrieve matched object
console.log(a); // return array of matched objects
if (_.isEmpty(a)) { // if a is empty (no-match) then insert i into collection C. The newly created documents will show at auto suggestion after submit event. there is no 'no-match' again after this
  return C.insert
} else {    // if a not empty then add i into list
    _.forEach(a, function(x) {
    // Code adding i into collection list. List.insert...
  });
}

thankYou...

MeKarina avatar Nov 18 '15 13:11 MeKarina