Skip to content

Instantly share code, notes, and snippets.

@harryadel
Created September 30, 2019 16:00
Show Gist options
  • Select an option

  • Save harryadel/4a406afc52b873cd60ea3b0feecd05d0 to your computer and use it in GitHub Desktop.

Select an option

Save harryadel/4a406afc52b873cd60ea3b0feecd05d0 to your computer and use it in GitHub Desktop.

Revisions

  1. harryadel created this gist Sep 30, 2019.
    36 changes: 36 additions & 0 deletions example
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    // Rendered DOM
    // example.html
    <div class="product">
    <img src="{{productImageSource}}" />
    <h4>Title</h4>
    <p>Price {{productPrice}}</p>
    <button class="add">+</button>
    <input type="number" id="quantity" />
    <button class="subtract">-</button>
    <span class="subtotal">Subtotal</span>

    <div class="actionButtons">
    <button>Update</button>
    <button>Delete</button>
    </div>
    </div>


    // example.js

    Template.example.events({
    'click .add'(event, templateInstance) {
    let currentValue = $(event.currentTarget)
    .parent()
    .siblings(".subtotal")
    .val() // not sure val() or text()

    $(event.currentTarget)
    .parent()
    .siblings(".subtotal")
    .val(currentValue + 1);
    },
    'click .subtract'(event, templateInstance) {
    // same as above except we subtract ofc
    }
    })