1
Great, I got a problem. I already have on the site a Search field in Ajax that works perfectly, when I type it already makes the search. OK.
However I am implementing this on a WP site, and put via jQuery the code below to assign a value to the field and simulate the enter key for search. But it doesn’t work. If I give you a space that is and enter, say so. Follow my code, you could give me a clue.
PS: I don’t have a boot
/* PREENCHE AUTOMATICAMENTE O NOME DO CURSO / CALENDARIO */
jQuery(document).ready(function($) {
jQuery("#mec_sf_s_9741").attr('value', 'Teste 1');
var e = $.Event( "keyup", { keyCode: 13 } );
jQuery('#mec_sf_s_9741').trigger(e);
});
Where this written Test 1 is already filled automatically.
Gratitude.
Don’t you have some WP script undoing the bind from the key? You’ve tried redoing bind through the console, after the page has fully loaded?
– Leandro Angelo
I’ve tried the bind event too and nothing.
– Luis Gustavo Leal
But you did what I said? let the page load, after downloading all Resources and then on the console run the block that is inside the ready.
– Leandro Angelo
Yes, via console after all loaded. It changes the value and does nothing else. Tbm shows no error. I can’t tell if the event is happening.
– Luis Gustavo Leal
Ok, but your goal is to submit the form in the enter keyup? What is the form id?
– Leandro Angelo
I have a search input fields that assign the value "XXX" via jquery after loading the page. I want to simulate that the user filled and gave enter! The code below works, but does not execute the search. jQuery( "input[id ='mec_sf_s_9901']" ).val( "SD" ); var e = jQuery.Event( "keypress", { keycode: 13 } ); jQuery(Document). on('keypress', Function(Event) { if ( Event.keycode == 13) { jQuery( "mec_sf_s_9901" ).Focus(); Alert("ENTER pressed..."); } }); // // press ENTER // jQuery(Document). Trigger(and);
– Luis Gustavo Leal
Isn’t it easier for you to submit the form or execute the method that does the search? You should not "simulate" user inputs and this is unnecessary if you have DOM control...
– Leandro Angelo
The problem is that I am using WP with the Plugin that does the search. Ex: I have 2 courses in google calendar, events start with AA or BB, so on the page if the user enters the AA course I want to display the next dates only for AA. So I need to autonomously fill the search field with AA and simulate enter for it to filter.
– Luis Gustavo Leal
read the documentation of the plugin, surely it should present a better way to do this
– Leandro Angelo
It does not have this feature, already informed (it only matters a calendar) I created this form adding the two letters at the beginning of the Event so I can filter between AA and BB. based on the page I seek AA or BB. Understood? I saw that the filter field fires an envelope called search(), but it doesn’t recognize this event directly in my code. Must be a function of the plugin itself. would make a "include" of the two classes?
– Luis Gustavo Leal