The code below works. The .on() function in JQuery is can attach the event. However, if I replace the combo with AJAX, I have to attach again. I would like to use the delegated version of the .on() function. In this example, The commented out code does not work. I also tried the delegate syntax that has been suggested elsewhere on this forum. I am using JQuery 1.7.1 specifically for the .on() functionality, and I have verified it works on normal html events. I am using 12.1 infragistics. I placed the script at the end to show that the script is executing after the MVC helper is done.
@{ var comboModel = new ComboModel { DataSource = new [] { "fee","fi", "fo","fum"}, InputName = "TestCombo", ID = "TestComoboTarget" };}<div id="comboTestContainer">@Html.Infragistics().Combo(comboModel)</div><script type="text/javascript"> $(document).ready(function () { //This code works $('span#TestComoboTarget').on('igcomboselectionchanged', function () { alert('hello'); }); //This does not work // $('div#comboTestContainer').on('igcomboselectionchanged', 'span#TestComoboTarget', function() { // alert('hello'); // }); //This also does not work // $(document).delegate("span#TestComoboTarget", "igcomboselectionchanged", // function (evt, ui) { // alert('hello'); // }); });</script>
Hi Chad,
I tested delegate and on functions under jquery 1.4.4 and 1.7.1.The delegate worked for 1.4.4, but did not for 1.7.1. I guess, support for that method was discontinued.The on with selector-parameter worked only for plain window events, like
<input type="button" id="evt" value="evt test" /><script type="text/javascript"> $(document).ready(function () { $(document.body).on('click', '#evt', function() { alert('click'); }); });</script>but it did not work for complex events similar to
<div id="slider"></div><script type="text/javascript"> $(document).ready(function () { $("#slider").slider(); $(document.body).on('slideslide', '#slider', function() { alert('slide'); });});</script>
But the on without selector-parameter (the very first your sample) worked ok. It is possible that there is a bug in jquery 1.7.1 with failure of complex events or docs have missing note, that complex events with selector-param are not supported.
Note: I suggest you do not use node-name prefix in selectors. You should use #TestComoboTarget, instead of span#TestComoboTarget or div#TestComoboTarget. The igCombo can be instantiated from DIV, but in case of Mvc combo helper, the SPAN is used, so, div#TestComoboTarget selector will fail.
Also,
Just to show I am reading the documentation, this page says that on() is supported and preferred to the delegate syntax in JQuery 1.7:
http://help.infragistics.com/NetAdvantage/jQuery/2012.1/CLR4.0?page=Using_Events_in_NetAdvantage_for_jQuery.html
However, no examples of on() syntax are given. The code samples show live() and die(). In the event page for igcombo, the delegate syntax is shown, but that does not seem to work in JQuery 1.7.
For grins, I tried this in the above example:
$(document).on('igcomboselectionchanged', 'span#TestComoboTarget', function() { alert('hello'); });
No, luck.