You are viewing limited content. For full access, please sign in.

Question

Question

Prevent empty lookup results from overwriting filled fields

asked on August 12, 2017

Is there a way to prevent a lookup rule from overwriting data with empty strings? I have several lookup rules that try to provide defaults for fields further down the form. If a user overwrites one of those defaulted fields, then jumps back up and changes a field that triggers one of those lookups, the later field is overwritten by the lookup, even if it didn't find a match.

I'm looking for a way to either prevent the lookup from replacing values with an empty string, or to use javascript to disable a particular lookup.

[v 10.2.1]

0 0

Answer

SELECTED ANSWER
replied on August 13, 2017

Hi Scott,

It's kind of difficult to prevent lookup when result is empty (that would require modifying original Forms code and lookup is too complicated to update), but there is an easy way to prevent lookup updating a field. Use script like this:

$('#q2 input').focusout(function(){
    $(this).attr('vo','k');
  });

q2 is the lookup rule target field. On focus out of the field, it will change the "vo" attribute to "k" which means keep current value. Then lookup result won't overwrite this field value.

2 0
replied on August 14, 2017

Thanks! Is there documentation anywhere that explains the magic of "attr('vo','k')"? In this case, I seem to get the same behavior by just setting the attr as when wrapping it in the focusout function.

0 0
replied on August 14, 2017

There is no documentation: this is not some kind of public interface Forms provided, and it is not guaranteed that this function will work the same way in future release. You might think of it as a "trick" to make lookup rule work in the expected way at this moment.

The "focusout" is used so that if the field is not manually updated, the lookup rule still work.

0 0
replied on November 7, 2018

Is there an equivalent that works in 10.3.1.635?

0 0
replied on June 16, 2021

Or one that works in 11?
The vo attribute is still there but doesn't seem to affect the overwrite behavior.

0 0
replied on July 15, 2021

The above code stopped working since 10.3.1 because of functional changes;

The workaround in 10.3.1 or later was to remove the 'change' event handler on the lookup rule trigger field (#q1 for example):

$('#q1 input').off('change').off('lookup')

If your custom script has set change event on the field, you need to add it back

1 0
replied on January 5, 2022 Show version history

@████████ to add change and lookup back to the element, do we use the ".on" or something else?

EDIT: I got it to work when an .on('change'... occurs (on the field I turned events off for), I trigger 'lookup', I have 2 fields that I need to trigger the lookup, that's why you see 2 below.

  $('.enterPO input').on("change", function(){
    if($(this).val()==""){
	$('.fyVendPOsVal input').on('change', function(){
    	$('.fyVendPOsVal input, .vendCode input').trigger('lookup');
    })
    }
    else {
		$('.fyVendPOsVal input').off('change').off('lookup');
    }
  })

Thanks

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.