aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-24 13:32:24 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-24 13:32:24 +0800
commit2a1be466fb989f9485468e30ddb40a68f3de8772 (patch)
treea094af8cd619e99966fc2c3ef078b238919872d4
parentfacd6960489d5949636d0b206e6650d215fe6fa3 (diff)
downloadfg21sim-2a1be466fb989f9485468e30ddb40a68f3de8772.tar.bz2
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.
-rw-r--r--fg21sim/webui/static/js/configs.js15
1 files changed, 9 insertions, 6 deletions
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) {