reblessed
reblessed copied to clipboard
Dynamically added form input elements are not included in focus cycle
After dynamically adding an input element (e.g. textbox) to a form, the new element is not present anywhere in the focus cycle.
This occurs because the dynamically built _children
array (which is used for focus cycling) on the form is not refreshed, even though the children
array is updated correctly. There's even an existing comment saying that the bypass of rebuilding the _children
array if one already exists on a refresh should possibly be removed.
Form.prototype._refresh = function () {
// XXX Possibly remove this if statement and refresh on every focus.
// Also potentially only include *visible* focusable elements.
// This would remove the need to check for _selected.visible in previous()
// and next().
if (!this._children) {
var out = [];
this.children.forEach(function fn(el) {
if (el.keyable)
out.push(el);
el.children.forEach(fn);
});
this._children = out;
}
};
Turns out the comment was spot on!
The fix is to simply remove the "if" condition around this, which rebuilds a correct _children
array of descendant inputs every time it is required. Will raise a PR for the fix shortly.