From bf2454720236d573465d36956aa15ff67edfb3d8 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 25 Dec 2018 19:02:05 +0000 Subject: [PATCH] The 'option' and 'editableOption' arguments can now specify a 'defaultIndex' to populate, instead of using the first in the provided list. --- src/core/Ingredient.mjs | 2 ++ src/core/Operation.mjs | 1 + src/web/HTMLIngredient.mjs | 7 ++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index 02359014..dda66b8f 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -25,6 +25,7 @@ class Ingredient { this.hint = ""; this.toggleValues = []; this.target = null; + this.defaultIndex = 0; if (ingredientConfig) { this._parseConfig(ingredientConfig); @@ -46,6 +47,7 @@ class Ingredient { this.hint = ingredientConfig.hint || false; this.toggleValues = ingredientConfig.toggleValues; this.target = typeof ingredientConfig.target !== "undefined" ? ingredientConfig.target : null; + this.defaultIndex = typeof ingredientConfig.defaultIndex !== "undefined" ? ingredientConfig.defaultIndex : 0; } diff --git a/src/core/Operation.mjs b/src/core/Operation.mjs index 3f5df52f..3f6b3e86 100755 --- a/src/core/Operation.mjs +++ b/src/core/Operation.mjs @@ -181,6 +181,7 @@ class Operation { if (ing.hint) conf.hint = ing.hint; if (ing.disabled) conf.disabled = ing.disabled; if (ing.target) conf.target = ing.target; + if (ing.defaultIndex) conf.defaultIndex = ing.defaultIndex; return conf; }); } diff --git a/src/web/HTMLIngredient.mjs b/src/web/HTMLIngredient.mjs index 13e16e3f..d026e1f3 100755 --- a/src/web/HTMLIngredient.mjs +++ b/src/web/HTMLIngredient.mjs @@ -26,6 +26,7 @@ class HTMLIngredient { this.disabled = config.disabled || false; this.hint = config.hint || false; this.target = config.target; + this.defaultIndex = config.defaultIndex || 0; this.toggleValues = config.toggleValues; this.id = "ing-" + this.app.nextIngId(); } @@ -133,7 +134,7 @@ class HTMLIngredient { } else if ((m = this.value[i].match(/\[\/([a-z0-9 -()^]+)\]/i))) { html += ""; } else { - html += ``; + html += ``; } } html += ` @@ -154,7 +155,7 @@ class HTMLIngredient { } else if ((m = this.value[i].name.match(/\[\/([a-z0-9 -()^]+)\]/i))) { html += ""; } else { - html += ``; + html += ``; } } html += ` @@ -170,7 +171,7 @@ class HTMLIngredient { class="form-control arg inline" id="${this.id}" arg-name="${this.name}" - value="${this.value[0].value}" + value="${this.value[this.defaultIndex].value}" ${this.disabled ? "disabled" : ""}> ${this.hint ? "" + this.hint + "" : ""}