Bug 784590 - No onchange event after seleted options by value selector(mozbrowser <select>), r=fabrice

This commit is contained in:
Shih-Chiang Chien 2012-09-05 14:10:55 +08:00
parent 0ec3169d22
commit 8f39d91f36

View File

@ -118,13 +118,28 @@ let FormAssistant = {
case "Forms:Select:Choice":
let options = target.options;
let valueChanged = false;
if ("index" in json) {
options.item(json.index).selected = true;
if (options.selectedIndex != json.index) {
options.selectedIndex = json.index;
valueChanged = true;
}
} else if ("indexes" in json) {
for (let i = 0; i < options.length; i++) {
options.item(i).selected = (json.indexes.indexOf(i) != -1);
let newValue = (json.indexes.indexOf(i) != -1);
if (options.item(i).selected != newValue) {
options.item(i).selected = newValue;
valueChanged = true;
}
}
}
// only fire onchange event if any selected option is changed
if (valueChanged) {
let event = content.document.createEvent('HTMLEvents');
event.initEvent('change', true, true);
target.dispatchEvent(event);
}
break;
}
},