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

How to subscribe to auxCollection, or specific subscription, on 'add new' form?

Open brylie opened this issue 10 years ago • 6 comments

I have a collection with a relationship field.When the 'create new' form for the collection renders, I want to provide a user select box containing the entity names from the referenced collection. However, the dropdown box does not populate when autopublish is disabled.

adminConfig.js

AdminConfig.js contains the correct collection in auxCollections.

Residents: {
      icon: "users",
      color: "red",
      auxCollections: ['Homes'],
      tableColumns: [
        {label: "First name", name: "firstName"},
        {label: "Last Initial", name: "lastInitial"}
      ],
      extraFields: ['homeId']
    },

Schema

The schema has an autoform options function that returns options for the select widget.

homeId: {
    type: String,
    label: 'Home',
    autoform: {
      options: function() {
        // Get all homes from related collection
      }
    }
  }

Screenshot

residents-create-new-missing-homes

brylie avatar Sep 03 '15 19:09 brylie

Hi, I had the same issue. Look at this thread in order to solve it (under "temporary solution"): https://github.com/yogiben/meteor-admin/issues/124 David

loevda avatar Nov 05 '15 11:11 loevda

Alright, I notice your router code looks like this:

Router.waitOn(function(){
    console.log('----------ROUTER waitOn subscriptions for admin'); // this is to verify in the console that this function is actually called > you can delete it after it's working
    return Meteor.subscribe('posts') // put here the subscription to all documents
}, {
    only: ['adminDashboard'] // this is the name of the yogiben:admin route
});

Routes may not be ideal for subscription management, e.g. when not using Iron Router. How can we hook in to the `template...created, in order to subscribe at the template level?

brylie avatar Nov 09 '15 10:11 brylie

If we do use routes, how do I hook in to a specific route? E.g. admin/Houses/add. Is there a way to handle this with a template level subscription?

brylie avatar Dec 01 '15 13:12 brylie

routes updated in readme https://github.com/yogiben/meteor-admin#custom-route-options

AdminConfig = {
  // ...
  collections: {
    Posts: {
      routes: {
        new: {
          waitOn: function () { return Meteor.subscribe('images'); }
        },
        view: {
          waitOn: function () { return Meteor.subscribe('images'); }
        },
        edit: {
          waitOn: function () { return Meteor.subscribe('images'); }
        }
      }
    }
  }
  // ...
}

HazemKhaled avatar Mar 20 '16 19:03 HazemKhaled

@HazemKhaled thanks for your response :-)

brylie avatar Mar 21 '16 11:03 brylie

@HazemKhaled how would you accomplish this for User's UserProfiles section?

johnmarty avatar Mar 05 '18 10:03 johnmarty