perak / kitchen-site

Meteor Kitchen site source code
MIT License
282 stars 38 forks source link

cant populate my dropdown value field with values from my collection #262

Open Maqhosha opened 8 years ago

Maqhosha commented 8 years ago

my collection looks like this. { "name": "tblCountry", "type": "collection", "fields": [ { "name": "cCountryName", "title": "Country Name", "type": "string", "required": true }, { "name": "cCountryCode", "title": "Country Code", "type": "string" } ], "roles_allowed_to_read": [ "nobody" ], "roles_allowed_to_insert": [ "owner" ], "roles_allowed_to_update": [ "owner" ] }, but its not working, please help, actually it looks like all my collection are not working, cause i even fill my dataview, sorry i'm new to meteor-kitchen

perak commented 8 years ago

@Maqhosha your collection looks good. What doesn't work? Do you have any error messages?

Maybe problem can be in naming convention: kitchen expects object names in "snake case" (instead tblCountry should be tbl_country, and the same for field names). Kitchen will properly generate your collection, but if you refer collection from another object (form, dataview etc.) by "camel case" name "tblCountry" then generator will not find it because name is internally stored in "snake case".

Maybe that's solution for your issue? Just convert all object names to "snake_case" and let me know.

Maqhosha commented 8 years ago

@perak I don’t get any errors maybe its the naming conversion. that means i must change everything from my project. Thank you i wil get back to you.

Maqhosha commented 8 years ago

is this the right way to get values form the collection to a select field?

```
perak commented 8 years ago

@Maqhosha If you are using "kitchen", there is "lookup field" in a form (see "example-invoices") - it will show data from the collection in select box in a form.

If you are doing manually (writing code without "kitchen"), correct way is:

<select name="countryId">
    {{#each countries}}
        <option value="{{_id}}">{{cCountryName}}</option>
    {{/each}}
</select>
Maqhosha commented 8 years ago

I think am going there thank you. but ist a must to use params?

Maqhosha commented 8 years ago

my problem is solved thank you perak, now i have a little problem on my private layout my routing is not working i cant access my pages

perak commented 8 years ago

@Maqhosha I cannot help you that way - you need to describe problem in details and give me steps to reproduce.

Maqhosha commented 8 years ago

okay here the peace of code, am now doing some touch ups meteor. when i add the new subscribe like that of sports_personality my page load forever, or am not allowed to add anything here other than the generated code?

isReady: function() {

    var subs = [
        Meteor.subscribe("countries"),
        //Meteor.subscribe("sports_personality"),
        Meteor.subscribe("teams"),
        Meteor.subscribe("sports"),
        Meteor.subscribe("players"),
        Meteor.subscribe("current_user_data")
    ];
    var ready = true;
    _.each(subs, function(sub) {
        if(!sub.ready())
            ready = false;
    });
    return ready;
},

data: function() {

    return {
        params: this.params || {},
        countries: TblCountry.find({}, {}),
        sports_personality: TblSportsPerson.find({}, {}),
        teams: TblTeams.find({}, {}),
        sports: TblSports.find({}, {}),
        players: TblPlayers.find({}, {}),
        current_user_data: Users.findOne({_id:Meteor.userId()}, {})
    };
perak commented 8 years ago

Do you have server-side publish code for these? ("sports_personality", "teams", ... ) ?

Maqhosha commented 8 years ago

@perak oh thank you everything is working fine now, the naming was different and i removed the if statement and returned only the TblSportsPerson.find... i thought "nobody" means everyone can access the collection but since i removed everything is working fine
Meteor.publish("sports_person", function() { if(Users.isInRoles(this.userId, ["nobody"])) { return TblSportsPerson.find({}, {}); } return this.ready(); }); thank you very much perak :+1: