methyl
methyl

Reputation: 3312

Weird form reset event behavior

I ran into weird problem when listening to form reset event.

Inside callback of reset event I check for input value, and it's not updated immediately, I have to wait until next tick, for example with setTimeout(callback, 0) or preventing default and triggering event manually with el.reset()

Here is jsbin example so you can see what I'm talking about - after you insert some value into input and click reset button, no content should be added to div element.

I can see the same problem on Chrome as well as Firefox.

Upvotes: 3

Views: 271

Answers (2)

test30
test30

Reputation: 3654

It seems that hack to this problem might be overriding onreset property.

There is no guarantee it works in other browers.

form.onreset=function(){
  var b = input.value;
  logger.innerHTML += b + "<br/>"; 
};

please find here example I've prepared http://jsbin.com/muzahuye/20/edit?html,js,output

works fine on firefox, at least 28

https://browserling.com/queue?uri=http%3A%2F%2Fjsbin.com%2Fmuzahuye%2F20%2F%3Foutput&browser=firefox&version=nightly

Upvotes: 1

DoctorMick
DoctorMick

Reputation: 6793

The reset event is called before anything is reset rather than after, to give you a chance to cancel the reset if you need to.

This SO question says the only way to do do something after the reset is to call a function on a timeout: Call a function after form reset

Upvotes: 2

Related Questions