mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Stop not updating form controls if they're focused
On Blaze, we copied functionality we had on Spark: Don't update form controls (INPUT, TEXTAREA) if they are focused and their underlying value reactively updates. This was never meant to be the eventual solution -- we'd eventually have a way to define strategies for two-way data binding. Maybe you'd be able to define a callback that notifies the app when a change happens to a field that hasn't been saved yet. Moreover, not only is the feature incomplete, but with Blaze it works much more poorly than in Spark. Due to fine-grained updates, users his this more frequently and don't seem to like the behavior (in Spark you would only hit this behavior if you set up your preserve rules exactly right, which many users did not do). So, we're just ripping out this functionality. Now if a field gets edited by some other user while you're focused it will just lose its value. Focus will remain. Fixes #1965
This commit is contained in:
@@ -1344,22 +1344,15 @@ _.each(['textarea', 'text', 'password', 'submit', 'button',
|
|||||||
test.equal(DomUtils.getElementValue(input), "This is a fridge");
|
test.equal(DomUtils.getElementValue(input), "This is a fridge");
|
||||||
|
|
||||||
if (canFocus) {
|
if (canFocus) {
|
||||||
// ...unless focused
|
// ...if focused, it still updates but focus isn't lost.
|
||||||
focusElement(input);
|
focusElement(input);
|
||||||
|
DomUtils.setElementValue(input, "something else");
|
||||||
R.set({x:"frog"});
|
R.set({x:"frog"});
|
||||||
|
|
||||||
Deps.flush();
|
Deps.flush();
|
||||||
test.equal(DomUtils.getElementValue(input), "This is a fridge");
|
test.equal(DomUtils.getElementValue(input), "This is a frog");
|
||||||
|
test.equal(document.activeElement, input);
|
||||||
// blurring and re-setting works
|
|
||||||
blurElement(input);
|
|
||||||
Deps.flush();
|
|
||||||
test.equal(DomUtils.getElementValue(input), "This is a fridge");
|
|
||||||
}
|
}
|
||||||
R.set({x:"new frog"});
|
|
||||||
Deps.flush();
|
|
||||||
|
|
||||||
test.equal(DomUtils.getElementValue(input), "This is a new frog");
|
|
||||||
|
|
||||||
// Setting a value (similar to user typing) should prevent value from being
|
// Setting a value (similar to user typing) should prevent value from being
|
||||||
// reverted if the div is re-rendered but the rendered value (ie, R) does
|
// reverted if the div is re-rendered but the rendered value (ie, R) does
|
||||||
|
|||||||
@@ -98,46 +98,19 @@ var SVGClassHandler = BaseClassHandler.extend({
|
|||||||
|
|
||||||
var BooleanHandler = AttributeHandler.extend({
|
var BooleanHandler = AttributeHandler.extend({
|
||||||
update: function (element, oldValue, value) {
|
update: function (element, oldValue, value) {
|
||||||
var focused = this.focused(element);
|
var name = this.name;
|
||||||
|
if (value == null) {
|
||||||
if (!focused) {
|
if (oldValue != null)
|
||||||
var name = this.name;
|
element[name] = false;
|
||||||
if (value == null) {
|
|
||||||
if (oldValue != null)
|
|
||||||
element[name] = false;
|
|
||||||
} else {
|
|
||||||
element[name] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// is the element part of a control which is focused?
|
|
||||||
focused: function (element) {
|
|
||||||
if (element.tagName === 'INPUT') {
|
|
||||||
return element === document.activeElement;
|
|
||||||
|
|
||||||
} else if (element.tagName === 'OPTION') {
|
|
||||||
// find the containing SELECT element, on which focus
|
|
||||||
// is actually set
|
|
||||||
var selectEl = element;
|
|
||||||
while (selectEl && selectEl.tagName !== 'SELECT')
|
|
||||||
selectEl = selectEl.parentNode;
|
|
||||||
|
|
||||||
if (selectEl)
|
|
||||||
return selectEl === document.activeElement;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Expected INPUT or OPTION element");
|
element[name] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var ValueHandler = AttributeHandler.extend({
|
var ValueHandler = AttributeHandler.extend({
|
||||||
update: function (element, oldValue, value) {
|
update: function (element, oldValue, value) {
|
||||||
var focused = (element === document.activeElement);
|
element.value = value;
|
||||||
|
|
||||||
if (!focused)
|
|
||||||
element.value = value;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user