Page 1 of 1

Can I fire events using Javascript?

Posted: Mon May 26, 2014 1:17 pm
by bahar.wadia

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.


Can I fire events using Javascript?

Posted: Mon May 26, 2014 3:02 pm
by Evgene Karachevtsev

Hello Bahar,

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


Can I fire events using Javascript?

Posted: Wed May 28, 2014 12:15 pm
by bahar.wadia

Can you please give an example how?

Thanks


Can I fire events using Javascript?

Posted: Wed May 28, 2014 2:43 pm
by Evgene Karachevtsev

Bahar,

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

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


Can I fire events using Javascript?

Posted: Thu May 29, 2014 2:12 am
by bahar.wadia

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.


Can I fire events using Javascript?

Posted: Thu May 29, 2014 4:45 am
by Yurii Orishchuk

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


Can I fire events using Javascript?

Posted: Thu May 29, 2014 11:24 am
by bahar.wadia

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.


Can I fire events using Javascript?

Posted: Thu May 29, 2014 4:09 pm
by Evgene Karachevtsev

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