i habe the collection of drinks , and the collection of order but i am not sure about how take order.
i wanna save a order with drinks, and the form input “cantidad” is the number of drinks, so the price x cantidad = $, i need to show the total cost of an order, how can i do this?
thanks for the help
I have the following simplified document i am using Meteor js with iron
the insert_order.html
<template name="InsertOrder">
<div>
<table class="table table-hover">
<thead>
<tr>
<th>Nombre</th>
<th>Valor</th>
<th>impuesto</th>
<th>cantidad</th>
</tr>
</thead>
<tbody>
{{#each drinks}}
<tr>
<td>{{nombre}}</td>
<td>$ {{price}}</td>
<td>{{impuesto}} %</td>
<td><form class="new-order">
<p><input name="cantidad" type="number" placeholder="Cantidad" /></p>
</form>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" data-action="drink/add">Pedido</button>
<button type="reset" class="btn btn-default" data-action="order/reset">Reset</button>
</div>
</template>
the js
the insert_order.js
Template.InsertOrder.events({
'submit .new-order'(event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form element
const nombre = nombre.drinks;
const price = price.drinks;
const impuesto = impuesto.drinks;
const number = target.number.value;
//const target = event.target;
// Insert a task into the collection
Order.insert({
nombre, price, impuesto, number,
createdBy: userId
});
// Clear form
//target.text.value = '';
},
"click [data-action='drink/add']": function () {
if
}
});
/* InsertOrder: Helpers */
Template.InsertOrder.helpers({
drinks: function(){
return Drinks.find();
}
});
drinks - collections
Drinks = new Mongo.Collection('drinks');
Drinks.attachSchema(new SimpleSchema({
nombre :{
type: String,
label: "Nombre",
max: 100
},
ingredientes:{
type: String,
label: "Ingredientes",
max: 1024
},
price:{
type: Number,
label: "$Valor",
},
impuesto:{
type: Number,
label: "%impuesto",
},
createdBy: {
type: String,
autoValue: function() {
return this.userId
}
}
}));
order collection
Orders = new Mongo.Collection('orders');
Orders.attachSchema(new SimpleSchema({
costo:{
type: Number,
label: "$Valor",
},
impuesto:{
type: Number,
label: "%impuesto",
},
cantidad:{
type: Number,
label: "cantidad",
},
createdBy: {
type: String,
autoValue: function() {
return this.userId
}
}
}));