Use of javascript magic hooks

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
gerardus
Posts: 20
Joined: 2013-11-11 08:29

Use of javascript magic hooks

Post by gerardus » 2014-06-11 16:42

Hi all,

Could the "magic" javascript described here http://bigprof.com/appgini/help/advance ... agic-files be used to set field values when another field changes?
If so, is there a reference somewhere?
Best regards,

Gerard.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Use of javascript magic hooks

Post by a.gneady » 2014-06-12 08:53

Yes it could, the "tablename-dv.js" file. Maybe something like this:

Code: Select all

jQuery(function(){
   jQuery('#field1').change(function(){
      jQuery('#field2').val('new value');
   });
});
In the above code, changing field1 would set field2 to 'new value'.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

gerardus
Posts: 20
Joined: 2013-11-11 08:29

Re: Use of javascript magic hooks

Post by gerardus » 2014-06-13 06:49

Thanks a lot, ahmad. I'll try it asap.

gerardus
Posts: 20
Joined: 2013-11-11 08:29

Re: Use of javascript magic hooks

Post by gerardus » 2014-06-13 09:08

Ok, here's the result of 1 hour of fumbling with javascript :oops: (simplified a lot for instructive purposes):

// Sets total field to read-only
document.getElementById("total").readOnly = true;

// set event hooks
$('qty').observe('change', qtyOrPriceChanged);
$('price').observe('change', qtyOrPriceChanged);

// hook function
function qtyOrPriceChanged(event) {
calc();
}

// calc function
function calc()
{
var qty = $("qty").value;
var price = $("price").value;
var total = qty * price;
$('total').value = total;
}

It works! (And it reminds me why I like Object pascal :twisted: ).

BTW, does anybody know if there is a way to get some error message when the javascript is incorrect, instead of nothing happening?

best regards,

Gerard.

gerardus
Posts: 20
Joined: 2013-11-11 08:29

Re: Use of javascript magic hooks

Post by gerardus » 2014-06-13 12:11

And trickier question: how could i detect a dropdown list (referenced table) changing?
Cheers,
Gerard.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Use of javascript magic hooks

Post by a.gneady » 2014-06-14 19:54

BTW, does anybody know if there is a way to get some error message when the javascript is incorrect, instead of nothing happening?
Install Firebug plugin for Firefox and open the console then reload the current page to see if there are any javascript error messages.
how could i detect a dropdown list (referenced table) changing
Lookups use "select2" component. Please refer to the events section of select2 documentation: http://ivaynberg.github.io/select2/#documentation
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

gerardus
Posts: 20
Joined: 2013-11-11 08:29

Re: Use of javascript magic hooks

Post by gerardus » 2014-06-16 08:07

Thx again, Ahmad.

gerardus
Posts: 20
Joined: 2013-11-11 08:29

Re: Use of javascript magic hooks

Post by gerardus » 2014-06-16 11:20

I'm sorry to bother you again, but I cannot find the select2 component in the loaded page.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Use of javascript magic hooks

Post by a.gneady » 2014-06-16 21:59

Use an expression like this:

Code: Select all

jQuery('#fieldname-container').select2('command');
Replace 'fieldname' above with the lookup field name, and "command" with the select2 command you want to execute (as detailed in the select2 documentation)
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

gerardus
Posts: 20
Joined: 2013-11-11 08:29

Re: Use of javascript magic hooks

Post by gerardus » 2014-06-17 06:36

Thanks!! :) :) :) :)

igimanigi
Posts: 11
Joined: 2016-11-30 18:24

Re: Use of javascript magic hooks

Post by igimanigi » 2016-12-15 16:07

Hi guys, i have stumbled on this thread and it happens to be something that i am fighting with for about 2 days now. I am trying to get the command for accessing the text of the selected value on the dropdown menu. I am only able to retrieve the ID using the 'val' command. Please help me. What is the command to get text. Also can i have a link to this documentation you speak of.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Use of javascript magic hooks

Post by DevGiu » 2016-12-18 10:58

I answered you in the other thread.
/Giuseppe
Professional Outsourcing Services

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: Use of javascript magic hooks

Post by xbox2007 » 2017-03-09 07:07

nice ,but i would like to ask
what if i would like change #field2 in other table .... ( not same table )

#field1 in table name ( AAAA )
#field2 in table Name ( BBBB )

if #field1 change , #field1 change ??????

Post Reply