Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Clear subform Lookup field when another subform lookup field is changed (on the same row)

Questions related to using nuBuilder Forte.
Post Reply
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Clear subform Lookup field when another subform lookup field is changed (on the same row)

Unread post by incoherence »

I have a subform with two Lookup fields, let's call them LOOKUP_A and LOOKUP_B
When the user changes the (looked up) value in LOOKUP_A, I want to clear (i.e. set to blank) LOOKUP_B on the same row.
I would like to do this in JavaScript if possible.
I am struggling with this simple task - any help appreciated... thanks!
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Clear subform Lookup field when another subform lookup field is changed (on the same row)

Unread post by kev1n »

Hi,

Add this JS in the LOOKUP_A's LUJS event:

Code: Select all

	  const sfId = 'sf_id'; // subform object id
	  const lookupB = 'id_lookup'; // LOOKUP_B id

	  objLookupB = $('#' + sfId + nuPad3(nuSubformRow) + lookupB);
	  if (!objLookupB.value) {
	      nuGetLookupId(null, objLookupB.attr('id'), false, false);
	  }
If LOOKUP_B also needs to be cleared when LOOKUP_A is cleared, you'll need to add an onchange event as well.
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Re: Clear subform Lookup field when another subform lookup field is changed (on the same row)

Unread post by incoherence »

I am not sure how it works exactly, but it does! Thanks so much, Kevin!

> const sfId = 'sf_id'; // subform object id
> const lookupB = 'id_lookup'; // LOOKUP_B id
> objLookupB = $('#' + sfId + nuPad3(nuSubformRow) + lookupB);

Here, is "nuSubformRow" a kind of "built-in" global variable that contains the (zero-based) subform row number?

I couldn't find nuPad3() but looks like it pads an integer to make it three digits (with leading zeros if required).

> if (!objLookupB.value) {

What is the purpose of this conditional, please?

(I think I need to go and read up more about jQuery to understand how the rest of the code works)
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Clear subform Lookup field when another subform lookup field is changed (on the same row)

Unread post by kev1n »

incoherence wrote: Sat Jan 07, 2023 4:01 am I couldn't find nuPad3() but looks like it pads an integer to make it three digits (with leading zeros if required).
Correct.
incoherence wrote: Sat Jan 07, 2023 4:01 am > if (!objLookupB.value) {

What is the purpose of this conditional, please?
! Is the logical NOT operator:

https://developer.mozilla.org/en-US/doc ... ogical_NOT

E.g. this

Code: Select all

! objLookupB.value
is the same as

Code: Select all

objLookupB.value != '' || objLookupB.value !== undefined || objLookupB.value !== null
The if statement checks if objLookupB.value is falsy (i.e., if it is null, undefined, 0, NaN, or an empty string). If objLookupB.value is not falsy, the code block inside the if statement is executed.
Post Reply