Page 1 of 1

OnChange for LookUp Field

Posted: 2022-08-10 19:55
by angus
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('');	
}

Re: OnChange for LookUp Field

Posted: 2022-08-10 20:10
by jsetzer
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.

Re: OnChange for LookUp Field

Posted: 2022-08-20 21:56
by Alisson
Try this:

Code: Select all

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

Re: OnChange for LookUp Field

Posted: 2022-09-14 14:11
by angus
Thanks Alisson, this worked for me!