bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Can I fire events using Javascript?

I want to know how to fire an event that belongs to a component, from Javascript.

I am using the Search component in my app. It works fine and does all the stuff I need it to do. From a usability perspective it leaves much to be desired. Why should the user have to close the keyboard and then try to touch the tiny little magnifying glass to Fire the Search event.

So now I am capturing key presses with

if (event.keyCode == 13) { //do something to fire the 'Search' event on the Search component }

However, I don't know now to fire the Search event from Javascript.

I hate to have to duplicate code which already exists for the Search event (also bad for maintenance). Can I use something like .tigger() or .fireEvent() or something else?

Thanks for your help.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Can I fire events using Javascript?

Hello Bahar,

Yes, you can fire event using JavaScript with .trigger() JQuery method: http://api.jquery.com/trigger/

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Can I fire events using Javascript?

Can you please give an example how?

Thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Can I fire events using Javascript?

Bahar,

codeApperyio('mobilebutton_3').trigger( "click" );/code

//where mobilebutton_3 - name of component which fire event "click" for

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Can I fire events using Javascript?

Sorry, but I have having trouble getting this to work.

Nothing happens.

I did try Appery vs Apperyio, which I believe is an error in the above example.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Can I fire events using Javascript?

Hi Bahar.

Currently it's not clear what do you mean by "Search" component. So you should describe it in details and provide us screen shots.

But if you talk about "Data filter" property for "list" component http://prntscr.com/3nlrv4/direct

You can use following code:

'''

//To set value into filter and trigger change event(get list to change in accordance with filter value).
Apperyio("mobilelist_2").parent("*").find(".ui-filterable input").val("1").trigger("change")

//To trigger change event(get list to change in accordance with filter value).
Apperyio("mobilelist_2").parent("*").find(".ui-filterable input").val("1").trigger("change")

'''

Regards

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Can I fire events using Javascript?

I am using the 'Search' component.

Image

It has an 'Event' 'Search'. All standard in Appery.

All I want to do is call the 'Search' event using JavaScript. Per you suggestion, I tried the following JavaScript in a Click event from a button

Appery('mobilesearchbar_Find').trigger("Search");

and

Appery('mobilesearchbar_Find').trigger("search");

Where ''mobilesearchbar_Find" is my 'Search component.

Neither works.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Can I fire events using Javascript?

Hello Bahar,

"Search" ivent in appery.io builder implement through "vclick" event. So you can you such code: $("#startScreen_mobilesearchbar_6-cover-img").trigger( "vclick" );
//where
// startScreen - name of your page
// mobilesearchbar_6 - name of search component

Return to “Issues”