You are correct that document ready shouldn't be used, this was just
a quick mock up. Regardless, this isn't the issue. I had posed the
question first in the dataTables forum, but they believe it's an
issue with JQM removing the events.
Fundamentally the issue is being caused because the input is being
given a type of 'search'. jQuery mobile has a list of input
types to degrade ($.mobile.degradeInputs). Search is an input in this
list to be degraded. The JQM function degradeInputsWithin copies the
HTML element, and replaces the type. However the issue is in this JQM
method the events are getting lost.
Set a breakpoint in the $.mobile.degradeInputsWithin function at
the line:
element.replaceWith( html.replace( findstr, repstr ) );
Before this line executes check the events associated to the input
($._data(this).events).
You will get an object with event listeners for cut, input, keypress,
keyup, paste and search. Go ahead and step over this line and check
the event listeners again - you don't.
I do expect JQM to change the look of the page, and manipulate the
DOM tree (that's why I'm calling enhancePageWithin in the
first place). I was not expecting degradeInputsWithin to lose the
event listeners for this object. It is a simple fix within
dataTables, if the search is defined with a type of 'text'
instead the input wouldn't be degraded.
However, I'm questioning whether the JQM functionality is
correct. Is degradeInputsWithin supposed to remove the previously
defined event handlers for an input? The documentation on the
function is a bit ambiguous
(
https://api.jquerymobile.com/jQuery.mobile.degradeInputsWithin/). It
indicates it removes undesirable native behavior - presumably this
means for example on a search field where chrome will also add an
'x'. But is the intention to actually lose the event
listeners, or was this merely an oversight i.e. bug?