From 822fc058c836e384899a8bad3960b2bb4e68ffc6 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Sat, 7 Jan 2012 04:35:24 +0100 Subject: [PATCH] Fixes form reset --- static/js/register.js | 47 ++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/static/js/register.js b/static/js/register.js index dbbfe01..f9911c8 100644 --- a/static/js/register.js +++ b/static/js/register.js @@ -1,26 +1,27 @@ $(document).ready(function() { - /* Customer selection */ - $("li.customer").click( function() { - /* Enable all buttons */ - $("li.customer").each(function(i) { - $(this).removeClass("selected"); - }); - /* Disable the customer button just clicked */ - $(this).addClass("selected"); - /* Update the form */ - $("input[name=customer]").val($(this).children("span.name").text()); - }); - /* Product amount controls */ - $("li.product").click( function() { - var form_field = $(this).children("input[type=text]"); - var qty = Number(form_field.val()) + 1; - form_field.val(qty); - }); - /* Also reset the hidden customer fields */ - $("input[type=reset]").click( function() { - $("input[name=customer]").val(""); - }); - - /* TODO: keyboard shortcuts */ + function enable_all_customers() { + $("li.customer").each(function(i) { + $(this).removeClass("selected"); + }); + } + /* Customer selection */ + $("li.customer").click( function() { + enable_all_customers(); + /* Disable the customer button just clicked */ + $(this).addClass("selected"); + /* Update the field */ + $("input[name=customer]").val($(this).children("span.name").text()); + }); + /* Product amount controls */ + $("li.product").click( function() { + var form_field = $(this).children("input[type=text]"); + var qty = Number(form_field.val()) + 1; + form_field.val(qty); + }); + /* Form reset */ + $("input[type=reset]").click( function() { + $("input[name=customer]").val(""); + enable_all_customers(); + }); });