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!
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
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)
-
- Posts: 22
- Joined: Sun May 08, 2022 2:36 pm
- Has thanked: 9 times
- Been thanked: 1 time
-
- nuBuilder Team
- Posts: 4294
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Clear subform Lookup field when another subform lookup field is changed (on the same row)
Hi,
Add this JS in the LOOKUP_A's LUJS event:
If LOOKUP_B also needs to be cleared when LOOKUP_A is cleared, you'll need to add an onchange event as well.
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);
}
-
- 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)
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)
> 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)
-
- nuBuilder Team
- Posts: 4294
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Clear subform Lookup field when another subform lookup field is changed (on the same row)
Correct.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).
! Is the logical NOT operator:incoherence wrote: ↑Sat Jan 07, 2023 4:01 am > if (!objLookupB.value) {
What is the purpose of this conditional, please?
https://developer.mozilla.org/en-US/doc ... ogical_NOT
E.g. this
Code: Select all
! objLookupB.value
Code: Select all
objLookupB.value != '' || objLookupB.value !== undefined || objLookupB.value !== null