javascript - Custom trigger event using prototype js not finding current pasted values -
i'm having issue version of prototype in richfaces 3.3.3.
the code list below worked fine before upgrading richfaces.
event.observe('#{formname}:suggest', 'paste', this.handlemousepaste.bind(this)); // trigger keyup event when user copy , pastes data field. (using mouse paste not work without fix) function handlemousepaste(event) { // element object event occured on var element = event.element(event); // trigger keyup event send ajax request server (event attached in richfaces code) triggerevent(element,'keyup'); } // create custom function allow trigger event anywhere in our javascript code function triggerevent(element,event){ if (document.createeventobject) { // dispatch ie var evt = document.createeventobject(); return element.fireevent('on'+event,evt) } else { // dispatch firefox + others var evt = document.createevent("htmlevents"); evt.initevent(event, true, true ); // event type,bubbling,cancelable return !element.dispatchevent(evt); } }
doing: handlemousepaste() firing keyup event attached input text field on page (via richfaces a4j:suppoer tag)
<h:inputtext value="#{mybean.typed}" id="suggest" styleclass="datatablefilterfield"> <a4j:support event="onkeyup" rerender="table1,tablescroller" ajaxsingle="true" requestdelay="200" ignoredupresponses="true" eventsqueue="filterqueue"/> </h:inputtext>
for reason not picking value paste input field 'suggest'. if paste in second time pick first value pasted in. example: if paste in 'tom', ajax request sends suggest field blank. pasting in 'tom2' can see suggest value been sent 'tom' (the field contains 'tomtom2').
like said, behaving fine before upgrading richfaces , therefore new version of prototype believe.
any ideas?
managed fix it. attaching has similar problem.
// attach js handlers when page content loaded (prototype.js framework) event.observe(window, 'load', function() { // attach event listener if element exists on page if ( $('#{formname}:suggest') ) { event.observe('#{formname}:suggest', 'paste', this.handlemousepaste.bind(this)); } }); // trigger keyup event when user copies , pastes data field. (using mouse paste not work without fix) function handlemousepaste(event) { // need put tiny delay in element has time pasted in content. settimeout(function() {this.triggerevent($('#{formname}:suggest'),'keyup')}, 10); } // create custom function allow trigger event anywhere in our javascript code function triggerevent(element,event){ if (document.createeventobject) { // dispatch ie var evt = document.createeventobject(); return element.fireevent('on'+event,evt); } else { // dispatch firefox + others var evt = document.createevent("htmlevents"); evt.initevent(event, true, true ); // event type,bubbling,cancelable return !element.dispatchevent(evt); } }
Comments
Post a Comment