fix call stack overflow on form focusing. fixes #38.
This commit is contained in:
parent
1bdba0dad0
commit
d624fe0c45
|
@ -4382,6 +4382,10 @@ Form.prototype.__proto__ = Box.prototype;
|
||||||
Form.prototype.type = 'form';
|
Form.prototype.type = 'form';
|
||||||
|
|
||||||
Form.prototype._refresh = function() {
|
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) {
|
if (!this._children) {
|
||||||
var out = [];
|
var out = [];
|
||||||
|
|
||||||
|
@ -4394,9 +4398,17 @@ Form.prototype._refresh = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Form.prototype._visible = function() {
|
||||||
|
return !!this._children.filter(function(el) {
|
||||||
|
return el.visible;
|
||||||
|
}).length;
|
||||||
|
};
|
||||||
|
|
||||||
Form.prototype.next = function() {
|
Form.prototype.next = function() {
|
||||||
this._refresh();
|
this._refresh();
|
||||||
|
|
||||||
|
if (!this._visible()) return;
|
||||||
|
|
||||||
if (!this._selected) {
|
if (!this._selected) {
|
||||||
this._selected = this._children[0];
|
this._selected = this._children[0];
|
||||||
if (!this._selected.visible) return this.next();
|
if (!this._selected.visible) return this.next();
|
||||||
|
@ -4419,6 +4431,8 @@ Form.prototype.next = function() {
|
||||||
Form.prototype.previous = function() {
|
Form.prototype.previous = function() {
|
||||||
this._refresh();
|
this._refresh();
|
||||||
|
|
||||||
|
if (!this._visible()) return;
|
||||||
|
|
||||||
if (!this._selected) {
|
if (!this._selected) {
|
||||||
this._selected = this._children[this._children.length - 1];
|
this._selected = this._children[this._children.length - 1];
|
||||||
if (!this._selected.visible) return this.previous();
|
if (!this._selected.visible) return this.previous();
|
||||||
|
@ -4439,11 +4453,13 @@ Form.prototype.previous = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Form.prototype.focusNext = function() {
|
Form.prototype.focusNext = function() {
|
||||||
this.next().focus();
|
var next = this.next();
|
||||||
|
if (next) next.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
Form.prototype.focusPrevious = function() {
|
Form.prototype.focusPrevious = function() {
|
||||||
this.previous().focus();
|
var previous = this.previous();
|
||||||
|
if (previous) previous.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
Form.prototype.resetSelected = function() {
|
Form.prototype.resetSelected = function() {
|
||||||
|
@ -4452,12 +4468,12 @@ Form.prototype.resetSelected = function() {
|
||||||
|
|
||||||
Form.prototype.focusFirst = function() {
|
Form.prototype.focusFirst = function() {
|
||||||
this.resetSelected();
|
this.resetSelected();
|
||||||
this.next().focus();
|
this.focusNext();
|
||||||
};
|
};
|
||||||
|
|
||||||
Form.prototype.focusLast = function() {
|
Form.prototype.focusLast = function() {
|
||||||
this.resetSelected();
|
this.resetSelected();
|
||||||
this.previous().focus();
|
this.focusPrevious();
|
||||||
};
|
};
|
||||||
|
|
||||||
Form.prototype.submit = function() {
|
Form.prototype.submit = function() {
|
||||||
|
|
Loading…
Reference in New Issue