From 2a1be466fb989f9485468e30ddb40a68f3de8772 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 24 Nov 2016 13:32:24 +0800 Subject: webui: configs.js: Trigger "Enter keypress" event after field updated When the value of a configuration field is updated by jQuery ".val()", trigger the "Enter keypress" event to update its related contents, e.g., the resolution note for "common/nside". Remove the wrong "Enter keypress" event triggering on page loading. --- fg21sim/webui/static/js/configs.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'fg21sim/webui/static') diff --git a/fg21sim/webui/static/js/configs.js b/fg21sim/webui/static/js/configs.js index a8ba933..781e334 100644 --- a/fg21sim/webui/static/js/configs.js +++ b/fg21sim/webui/static/js/configs.js @@ -147,7 +147,11 @@ var getFormConfigAll = function () { * Set the value of one single form field according to the given * name and value. * - * NOTE: Do NOT manually trigger the "change" event. + * NOTE: + * - Do NOT trigger the "change" event, which leads to recursive + * request/response between the client and server. + * - Trigger the "Enter keypress" event, to update the related contents, + * e.g., the pixel resolution note w.r.t. "common/nside" * * @param {String} name - The name of filed name * @param {String|Number|Array} value - The value to be set for the field @@ -183,6 +187,8 @@ var setFormConfigSingle = function (name, value) { } else { target.val(value); } + // Manually trigger the "Enter keypress" event to update related contents + target.trigger($.Event("keypress", {which: 13})); } else { console.error("No such element:", selector); } @@ -558,7 +564,7 @@ $(document).ready(function () { }); // Update the resolution note for field "common/nside" when press "Enter" - $("#conf-form input[name='common/nside']").keypress(function (e) { + $("#conf-form input[name='common/nside']").on("keypress", function (e) { if (e.which === 13) { var nside = parseInt($(this).val()); // Update the resolution note (unit: arcmin) @@ -566,10 +572,7 @@ $(document).ready(function () { $(this).closest(".form-group").find(".note > .value") .text(resolution.toFixed(2)); } - }).trigger( - // Manually trigger the "Enter" keypress event after loading page - $.Event("keypress", {which: 13}) - ); + }); // Update the maximum multiple "common/lmax" when "common/nside" changed $("#conf-form input[name='common/nside']").on("change", function (e) { -- cgit v1.2.2