OnChange for LookUp Field

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

OnChange for LookUp Field

Post by angus » 2022-08-10 19:55

Hi everyone, I have tried to use jsetzers code but I am not understanding fully. I have 2 select2 lookup fields

What I want is if someone changes the contract field on edit/update then the calue of the Codes field is set to empty.

This is what I have so far, but its not working, no error messages either.

can anyone point me in the right direction?

Code: Select all

var dv = AppGiniHelper.DV;
dv.ready(onReady);
function onReady() {
    type_id_init();
}

function type_id_init() {
    var fieldname = "Contract";
    var field = new AppGiniField(fieldname);
    // register onChangeHandler (listener)
    field.onChange(onTypeIdChanged);
}


function onTypeIdChanged() {
    hideOrShowFields();
}

function hideOrShowFields() {
 
    // fade in common fields
    $j('#Codes').val('');	
}
AppGini 22.13

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: OnChange for LookUp Field

Post by jsetzer » 2022-08-10 20:10

For narrowing down, can you please first of all check if hideOrShowFields() gets called at all. For example put alert('changed'); there.

If so, I'm afraid setting val to empty string will not be enough to clear a select2 selection in UI.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Re: OnChange for LookUp Field

Post by Alisson » 2022-08-20 21:56

Try this:

Code: Select all

$j(function(){
  $j('#Contract-container').on('change', function(){
    setTimeout(function () {
      $j('#Codes-container').select2('data', {id: 0, text: ''});
    },200)
  });
})

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: OnChange for LookUp Field

Post by angus » 2022-09-14 14:11

Thanks Alisson, this worked for me!
AppGini 22.13

Post Reply