perak / kitchen-examples

Meteor Kitchen examples
164 stars 115 forks source link

Invoice Example - Invoice Number - helper code on insert_form not working #55

Closed deviousjack closed 7 years ago

deviousjack commented 7 years ago

The helper code on the insert_form on the invoice example is not working:

              'nextInvoiceNumber': function() { var max = 0; var
              invoiceNumbers = Invoices.find({}, { fields: { invoiceNumber:
              1 }}).fetch(); _.each(invoiceNumbers, function(doc) { var
              intNum = parseInt(doc.invoiceNumber); if(!isNaN(intNum) &&
              intNum > max) max = intNum; }); return max + 1; }

Please help me get this working like the example you have.

perak commented 7 years ago

Hi @deviousjack excuse me for late answer.

I just built invoices example, and next invoice number works properly. Do you have any error messages or... what doesn't work?

If you are trying to build "react" application (using meteor-kitchen's --react switch) this code will not work (this example is ancient from early beginning of meteor-kitchen and from pre-React ages)

deviousjack commented 7 years ago

Hi @perak In the above code the 'nextInvoiceNumber' : portion comes up with the errors in the code editor "expected an assignment or function call and instead saw an expression", "missing semicolon", and "expected '(end)' instead saw ':' ".
My code is exactly the same as in the invoice-example. I am using blaze. I would like it to work like your working example. I have no idea why it isn't. Thank you so much Petar. I hope you can find the answer.

deviousjack commented 7 years ago

Hi @perak. I Solved the problem. In the default value field I had {{nextinvoiceNumber}} instead of {{nextInvoiceNumber}} so the javascript helper is correct. My insertion of the default value was wrong. Sorry about having you look at the javascript. It was my mistake, but it cost me at least a full day of trying different things. Cheers, Jack