p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

preventDefault for input

Open lmccart opened this issue 12 years ago • 6 comments

I removed the prevent default calls as they were breaking functionality of the page sometimes. but we might want some way to specify this as the user.

https://github.com/lmccart/p5js.org/issues/34 https://github.com/lmccart/p5.js/commit/f431979f93ef273c7835c966b85f90a47baebdec

lmccart avatar Jul 31 '14 17:07 lmccart

Cant the user do it inside the user defined function. i.e. button.mouseClicked(userFunc); function userFunc(e) { e.preventDefault(); }

I mean what is wrong with this? Anyhow the use will need to pass some parameter even if we decide to do this as a part of internal code. We will only complicate things for ourselves. Makes sense?

P.S. I can still see the preventDefault for touch methods. Are those left out on purpose?

hrishit avatar Aug 21 '14 07:08 hrishit

yes, I think you're right! maybe all that's needed then is some explanation / examples in the reference showing how to do this.

I left it on for touch because the default behavior conflicts more than with mouse. for example, if you defined a touchMoved event on mouse, moving your finger around the screen will also drag the frame around on safari. I thought it might be better for it to just work for beginners rather than having to add the preventDefault workaround. it does leave the question of how you might restore the default if you did want the behavior though.

lmccart avatar Aug 21 '14 15:08 lmccart

hmmm...makes sense. And I was also thinking of something like having a "forcedefault" kind of function or documenting it if JS provides it internally. Will update the thread if find one or a feasible solution.

hrishit avatar Aug 23 '14 18:08 hrishit

Sorry, got busy with other things in between. There's no simple way of restoring the default event in JS, at least I did not find any. Here is what we can do: we can listen to the mouseclick function by user and if we get false as a response then refrain from doing the preventDefault. If this seems valid then I'll make the changes and submit a pull request.

hrishit avatar Sep 03 '14 14:09 hrishit

ah ok, so let me make sure I understand, we could set up it so if a user defines a function like

function mousePressed() {
  // do some stuff
  return false;
}

then the default would be prevented, but without that return false line the default would fire too?

I think this sounds great, and is a little simpler than calling e.preventDefault().

lmccart avatar Sep 04 '14 11:09 lmccart

closed with https://github.com/lmccart/p5.js/pull/352, nice!

lmccart avatar Sep 05 '14 21:09 lmccart