Challenge Resetting Dropdown Lists in Repeating Rows in a Table

Hello!
I have built a table and for each row in the table, I have a dropdown list, with static options, in one of the columns.

Oddly, I’m having a challenge restoring the ‘default’ value of the dropdown list when the user cancel’s their ‘transaction.’ For example, if the user were to cancel out of the scenario below (captured first screenshot) and returned to the screen, the first row in the table would be set to ‘e-Sign,’ rather than the default value of ‘None.’ Even worse, if the user were to open the popup from a record with different documents in the table, the first dropdown list would still be selected as ‘e-Sign’

I’ve attempted 'reset relevant inputs’ and ‘reset group/popup’ combinations in a workflow that fires through the “when popup closes’ event; i’m not seeing any changes with the attempts.

How do I ensure that all of these drop downs are reset to their default value, each time this popup window renders?

Here is how the table and dropdown list are implemented…

Hello, how are you?

The only native way I found to do this in Bubble, based on what you described, was by clearing the repeating group and then displaying it again.

This way, you bring back the repeating group’s data and clear the dropdown.

Would this work for you? If not, we can think of another approach.

@carlovsk.edits , thank you! I really like the idea.

So, I gave it a shot (workflow below) but I still got the same results. I even tried tossing in some ‘reset relevant inputs’ into the mix.

Thank you again.

You can not reset specific inputs from a specific cell from outside the cell. You can check out how to write JavaScript and then use Toolbox plugin or free plugin like Orchestra.

You mentioned a table. Well, I haven’t used table element in a while (I need to test the new updates). But if that’s your case, I’m not sure if my suggestion will solve your problem. However, for Repeating Group it works.

So, maybe this plugin is all you need.

1 Like

I had tested it before using clear list and then display list, and that worked fine, but yes, the other (and better) way is using Run JavaScript.

Here’s the JavaScript code I made for the Run JavaScript action (Toolbox plugin). It should help you:

// param1 = dropdown IDs (e.g., "dd_1, dd_2" or "dd_*")
// param2 = value to apply (if empty/undefined/null -> clear)

(function () {
  // --- parameter intake ---
  const idSource = properties && properties.param1;
  const rawIds = String(
    Array.isArray(idSource) ? idSource.join(",") : (idSource ?? "")
  )
    .split(/[\n,]/)
    .map(s => String(s || "").trim())
    .filter(Boolean);

  const desired =
    properties && (properties.param2 !== undefined && properties.param2 !== null)
      ? String(properties.param2)
      : "";

  // --- helpers ---
  function fire(el, type) {
    try { el.dispatchEvent(new Event(type, { bubbles: true })); } catch(_) {}
  }

  // Return ALL elements that:
  // - have an exact ID match, or
  // - (if token ends with "*") start with the given prefix
  // - fallback: if no exact match, treat token as a prefix
  function resolveTargets(idToken) {
    if (!idToken) return [];

    if (idToken.endsWith("*")) {
      const prefix = CSS.escape(idToken.slice(0, -1));
      return Array.from(document.querySelectorAll(`[id^="${prefix}"]`));
    }

    const exact = CSS.escape(idToken);
    const exactList = Array.from(document.querySelectorAll(`[id="${exact}"]`));
    if (exactList.length) return exactList;

    return Array.from(document.querySelectorAll(`[id^="${exact}"]`));
  }

  // Ensure a hidden <option value="null"> exists (valid JSON), select it, and fire "change" only
  function clearSelectSafely(selectEl) {
    let opt = selectEl.querySelector('option[data-tmp-null="1"]');
    if (!opt) {
      opt = document.createElement("option");
      opt.value = "null";      // JSON.parse("null") => null
      opt.text = "";           // appears visually empty if shown
      opt.hidden = true;       // keep it out of the dropdown list
      opt.setAttribute("data-tmp-null", "1");
      selectEl.appendChild(opt);
    }
    selectEl.value = "null";
    fire(selectEl, "change");
    return true;
  }

  function setSelectValue(selectEl, valueStr) {
    const v = String(valueStr || "");

    // clear selection safely (avoid Bubble's JSON.parse errors)
    if (v === "") {
      return clearSelectSafely(selectEl);
    }

    // 1) try by value
    const byValue = Array.from(selectEl.options).find(o => String(o.value) === v);
    if (byValue) {
      selectEl.value = byValue.value;
      fire(selectEl, "input");
      fire(selectEl, "change");
      return true;
    }

    // 2) try by visible text
    const byText = Array.from(selectEl.options).find(o => String(o.text).trim() === v);
    if (byText) {
      selectEl.value = byText.value;
      fire(selectEl, "input");
      fire(selectEl, "change");
      return true;
    }

    return false;
  }

  // Generic support (if the “dropdown” is another control)
  function setGeneric(el, valueStr) {
    const v = String(valueStr || "");
    if (el.tagName === "INPUT" || el.tagName === "TEXTAREA") {
      el.value = v;
      fire(el, "input");
      fire(el, "change");
      return true;
    }
    const innerSelect = el.querySelector && el.querySelector("select");
    if (innerSelect) return setSelectValue(innerSelect, v);
    return false;
  }

  // --- apply to targets ---
  const targets = rawIds.flatMap(resolveTargets);

  targets.forEach(el => {
    if (!el) return;

    if (el.tagName === "SELECT") {
      setSelectValue(el, desired);
      return;
    }

    const selectInside = el.querySelector && el.querySelector("select");
    if (selectInside) {
      setSelectValue(selectInside, desired);
      return;
    }

    setGeneric(el, desired);
  });
})();

In param1, you set the dropdown IDs:


You can also use just one ID if needed.

And for the param2 value (the value you want in those dropdowns), you can set something like None, and all dropdowns with the provided IDs will take that value.
If you leave the value empty (as shown in the image below), all those dropdowns will be cleared:

1 Like

Thank you both so much! Though, I’m hesitant to introduce JS to start controlling things in bubble that, I think, should simply work… 1.) I’m no JS expert and worry that I could easily make things worse :slight_smile: 2.) I worry about bubble deploying changes that may cause the JS to fail unexpectedly in the future.

I love that you all are here to solve these types of problems but I’m going to think of different approaches that won’t require me to touch code (a scary thought!).

Thank you again.

Check out free plugin called Orchestra

1 Like

Does the same problem occur if the dropdown uses a dynamic list instead of a static list?

1 Like

Will do.

It is a static list already.

It took me some faffing about before coming up with this …

In the dropdown set a “Conditional” of Popup A isn’t visible. Set “Choices” to have just one entry: the default value (Turkey in my example).

When the popup closes, the dropdown source is effectively wiped out, including any selections made. The user may get to see the dropdown resetting.

A variation is set an empty list in the conditional, to show the placeholder text.

When the popup reopens, the conditional no longer applies, and the original source list is restored.

If wanting to reset without closing the popup, set up a workflow to turn off a boolean custom state, pause 50ms, turn on the custom state, add the custom state as another conditional.

NOTE: A workflow with pausing may be needed, depending on how the app saves the user selections.

thank you @mishav , i will give this a shot when i get back to this work item.