Event On click behavior with selector

25 views
Skip to first unread message

kstubs

unread,
Nov 3, 2012, 1:51:08 PM11/3/12
to prototype-s...@googlegroups.com
If I define an on click event for a given css selector did I disable or trap the default click event?  Reason I'm asking is I have a form and I have wired up a click event for a given input type like this:

this.form.on('click', 'input[type=checkbox]' ,functionChkClicked);

Now my radio clicks aren't working.  I can click one item in a radio group but when I try to click a different item in the same group it doesn't work.  

Ideas?
Karl..

fntzr

unread,
Nov 3, 2012, 2:06:36 PM11/3/12
to prototype-s...@googlegroups.com
try 'change' event.

kstubs

unread,
Nov 3, 2012, 2:19:10 PM11/3/12
to prototype-s...@googlegroups.com
@mikhail, please elaborate

On Saturday, November 3, 2012 11:06:48 AM UTC-7, mikhail wrote:
try 'change' event.

Walter Lee Davis

unread,
Nov 3, 2012, 2:29:07 PM11/3/12
to prototype-s...@googlegroups.com
Can you show the definition of your method functionChkClicked? Also, what do your see in your browser console? You should see an error there if that's why your function isn't returning. And no, an observer like this will only stop the default behavior if that's what you tell it to do. Otherwise, the event bubbles right on through.

Walter

kstubs

unread,
Nov 3, 2012, 2:36:59 PM11/3/12
to prototype-s...@googlegroups.com
No errors in console.  I assumed that defining the click event for a given css selector would not have an effect on the normal click behavior.

Relevant code:

var chkClicks = this.__chkClicks.bindAsEventListener(this);
this.__z__chkClicksthis = this.form.on('click','input[type=checkbox]',chkClicks);


__chkClicks: function(e) {
var elm = e.findElement();
this.form.select('div.container').invoke('hide');
this.form.select('input[type=checkbox]').without(elm).each(function(chk) { chk.checked = false; });
var chk_val = elm.getValue();
var show_layer = 'div.' + chk_val + '_container';
this.form.down(show_layer).show();
switch(chk_val) {
case 'athlete':
$('qf_athlete').show();
var input = $('qf_athlete').down('input');
Form.Element.setValue(input,(_msoC.msouser.name));
this.__qf.Search(Form.Element.getValue(input));
break;
}
},

Victor

unread,
Nov 12, 2012, 3:38:40 AM11/12/12
to prototype-s...@googlegroups.com
  1. How checkbox is related to clicks on radio buttons?
  2. bindAsEventListener(this) isn't needed - bind(this) is enough.
  3. Handler in Element#on retrieves clicked element as second argument, no need to find it via var elm = e.findElement();
  4. elm.getValue() for checkbox will return true or false - case 'athlete' has no sense - is this OK?

this.__z__chkClicksthis = this.form.on('click','input[type=checkbox]', this.__chkClicks.bind(this));

__chkClicks: function(e, elm) {
this.form.select('div.container').invoke('hide');
this.form.select('input[type=checkbox]').without(elm).invoke('setValue', false);
var chk_val = elm.getValue();
var show_layer = $F(elm) ? 'div.true_container' : 'div.false_container';
this.form.down(show_layer).show();
switch(chk_val) {
case 'athlete':
var input = $('qf_athlete').show().down('input');
input.setValue(_msoC.msouser.name);
this.__qf.Search(input.getValue());
break;
}
},
 
Reply all
Reply to author
Forward
0 new messages