propertychange and the hybrid dropdown

Apr 26, 2011 at 6:59 PM

Hello Marc,

Thanks again for the library.

I have a question about the example of your SPCascadeDropdowns function and its use of propertychange for the hybrid dropdowns...

I've used your example to bind a '(*)change' event to the control, but I've noticed that making a change to a hybrid dropdown triggers the event several times [due to onfocusout, onkeypress, onchange, ondblclick on the input and select objects].  So my question is... Am I missing something...is this being handled in some function I didn't notice? 

// AFTER VERIFYING THIS OBJECT IS HYBRID DROPDOWN
$('input[title="NCDR Number"]').bind('propertychange', function() {
    ... misc function call. 
});

the function makes several GetListItems calls.

Since I couldn't figure how you were dealing with the multiple events, I ended up wrapping my function call with a conditional statement to check which property is being changed

// AFTER VERIFYING THIS OBJECT IS HYBRID DROPDOWN
$('input[title="NCDR Number"]').bind('propertychange', function() {
  if( event.propertyName.toLowerCase() == "value" ){
    // ONLY EXECUTE FUNCTION IF THE 'VALUE' ATTRIBUTE CHANGES
    ... misc function call.
  }
});

I would appreciate if you can shed some light on the proper direction to deal with this issue.

Thanks,

J

BTW:  considering the ambiguity of my username, the male pronouns would be correct :)

Coordinator
Apr 26, 2011 at 8:08 PM

jenglish:

I wrestled with this, of course, when I was originally building SPCascadeDropdowns. The way I solved it in that case was to add an attribute to the element which I could check to see if anything had, in fact, changed. The code for this in v0.6.1 is at line 1358:

  if(parentSelect.Obj.attr("SPCascadeDropdown_Selected_" + childColumnStatic) === parentSelectSelected.join(";#")) {
   return;
  }
  parentSelect.Obj.attr("SPCascadeDropdown_Selected_" + childColumnStatic, parentSelectSelected.join(";#"));

Does this help?

M.

Apr 26, 2011 at 8:31 PM

Marc,

thanks!  Took me a few minutes (courtesy of a good lunch of Dim Sum), but I see it now...

You saved the value into a new attribute and as the event is triggered multiple times, if the event is a repeat then the function breaks.   Way better.   thanks again.

Coordinator
Apr 26, 2011 at 9:00 PM

Glad it makes sense. Let me know how it goes!

M.