Closed
Bug 11231
Opened 25 years ago
Closed 25 years ago
javascript watch handler not fired for INPUT TYPE="text" element
Categories
(Core :: Layout: Form Controls, defect, P3)
Core
Layout: Form Controls
Tracking
()
VERIFIED
INVALID
People
(Reporter: martin.honnen, Assigned: pollmann)
References
()
Details
Attachments
(2 files)
Javascript 1.2 introduced
Object.watch ('propertyname', function watchHandler(propName, oldValue,
newValue))
which is supposed to work for all objects including client side objects as FORM
elements.
Unfortunately as the example shows, the watch handler is not fired:
<SCRIPT>
function unchangedHandler (prop, oldValue, newValue) {
dump (this + '.' + prop + ' change attempt ' + oldValue + '->' + newValue+ '
prevented.');
return oldValue;
}
var x = new Object ();
x.prop = 'Kibology';
</SCRIPT>
</HEAD>
<BODY ONLOAD="document.aForm.aField.watch ('value', unchangedHandler); x.watch
('prop', unchangedHandler)">
<FORM NAME="aForm">
<INPUT TYPE="text" NAME="aField" VALUE="Kibology">
<BR>
<INPUT TYPE="button" VALUE="change variable"
ONCLICK="if (x.prop == 'Kibology') x.prop = 'Scriptology'; else x.value =
'Kibology';"
>
</FORM>
Try changing the text field's value and nothing happens. Compare to changing the
variable with a button press.
I filed that on form controls as it is neither a core js nor a DOM issue as that
doesn't treat watch.
Reporter | ||
Comment 1•25 years ago
|
||
Updated•25 years ago
|
Assignee: karnaze → pollmann
Comment 2•25 years ago
|
||
Eric, work with Steve on this or reassign if appropriate.
Assignee | ||
Updated•25 years ago
|
Status: NEW → RESOLVED
Closed: 25 years ago
OS: Windows 95 → All
Hardware: PC → All
Resolution: --- → INVALID
Assignee | ||
Comment 3•25 years ago
|
||
Are you referring to this description of the watch method?
http://developer.netscape.com/docs/manuals/communicator/jsguide/methods.htm#1005
870
watch
Core method of all objects. Watches for a property to be assigned a
value and runs a function when that occurs.
<SNIP>
Description
Watches for assignment to a property named prop in objectReference,
calling handler(prop, oldval,newval) whenever prop is set and storing
the return value in that property. A watchpoint can filter (or nullify)
the value assignment, by returning a modified newval (or oldval).
<SNIP>
I'd argue that this definition explicity excludes the type of notification that
is reported in this bug. The definition says "Watches for *assignment to* a
property". The example you posted never assigns a value to the text input's
value attribute. The attribute changes, yes, but there is no assignment. Thus,
the watch handler should not be called.
To show that we are indeed doing the "right thing" here check out the
modification of your example I'm attaching. It uses javascript to *assign to*
the value property of the element, and the handler attached to this value change
dutifully gets called.
Note that the way we are handling the watch method now in Seamonkey is identical
to the way it is handled in Nav 4 (watch isn't implemented in IE), so this
behaviour also follows precedent.
You can trap changes to the value of a text input (a desirable thing to do) by
registering under the onkeydown, onkeyup, and onmouseup events. This should
capture any changes of interest.
Assignee | ||
Comment 4•25 years ago
|
||
Updated•25 years ago
|
Status: RESOLVED → VERIFIED
Comment 5•25 years ago
|
||
verified invalid
You need to log in
before you can comment on or make changes to this bug.
Description
•