Wondering what is the best way to react to field changes and do
something with the field.
i was trying Form.Observer, however it looks like this only gets
passed the serialized contents of the form, not the actual element
which was changed. Am I missing something?
new Form.Observer($(form), 0.3, function(form, value){
console.log(value);
});
What would you suggest as as the best route? Whenever a field in my
form is changed I want to do some checks based on it's class, so I
need to return the element.
Should I assign a listener to each field? Should I try to get it to
work with one listener and use bubbling?
Thanks.
on 2008-06-10 17:23
on 2008-06-10 18:02
Bubbling seems like the answer to me. Put any listeners you need (change, select, click, etc.) on the form element, and then in your callback, use event.element() to get the source element. From there you can look at the new value. -Fred On Tue, Jun 10, 2008 at 10:22 AM, louis w <louiswalch@gmail.com> wrote: > Should I assign a listener to each field? Should I try to get it to > work with one listener and use bubbling? -- Science answers questions; philosophy questions answers.
on 2008-06-10 20:43
I think this should be "fixed". Knowing which element was changed is
often crucial. I'll make a patch as soon as I get a chance. Meanwhile,
you can use this as a workaround:
new Form.Observer($(form), 0.3, (function(){
var previousValue = $(form).serialize(true), element;
return function(form, value) {
value = value.parseQuery();
for (var prop in value) {
if (value[prop] !== previousValue[prop]) {
element = $(form).down('[name=' + prop +']');
break;
}
}
previousValue = value;
// use "element" variable which references changed element
}
})());
Best,
kangax
on 2008-06-10 20:56
Thanks kangax, nice to see this was already addressed. Do you know if it is included in any of the stable releases? In the meantime I will use your suggestion - which works perfectly.
on 2008-06-10 21:24
I agree this would be nice on the Periodical Observer, but I think
what the initial reply was hinting at was this:
$('myform').observe('change',
function(evt){
alert(evt.element().id);
}
);
Walter
on 2008-06-11 01:46
On Jun 11, 2:02 am, "Frederick Polgardy" <f...@polgardy.com> wrote:
> Bubbling seems like the answer to me. Put any listeners you need (change,
The change event doesn't bubble in the MS HTML DOM.
--
Rob
on 2008-06-11 02:06
You know, I did run into this about three months back on a web project I was working on. Extremely annoying indeed! Thanks for the clarification. On Tue, Jun 10, 2008 at 6:46 PM, RobG <rgqld@iinet.net.au> wrote: > > On Jun 11, 2:02 am, "Frederick Polgardy" <f...@polgardy.com> wrote: > > Bubbling seems like the answer to me. Put any listeners you need > (change, > > The change event doesn't bubble in the MS HTML DOM. -- Science answers questions; philosophy questions answers.
on 2008-06-11 05:35
This is not included anywhere yet. In the upcoming release we try to focus on bugfixes (and general polishing), so any enhancements will most likely have to wait for some time. I made a quick patch for this, but haven't had time to write unit tests yet. http://prototype.lighthouseapp.com/attachments/267... - kangax
on 2008-06-12 20:54
kangax, I noticed that if there are two inputs with the same name it will always return the first occurance of the double item. Even if the field you are updating is not one of the repeated items. Don't know if this will impact the patch too.
on 2008-06-12 23:55
Also, i am finding that it errors if your input name is an array. E.g. foo[bar] Do you know how to fix this. Should I apply the patch? Would that fix it?