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

Discussion

Discussion

Form lookup only runs when value is manually entered

posted on May 1, 2015 Show version history

I have two lookups on one form.  Since I have two lookups I altered the normal code to hide the Autofill buttons.  Also, I am copying the field value for the second lookup from another field. However, the lookup will only work when I manually enter the field value.  Here is the code that I am using to hide the Autofill buttons:

$(document).ready(function () {
  
   function autofill() {
    $('.autofill').trigger('click');
  }   
  $('.lookupCondition2').change(autofill);
});

UPDATE:

I've changed this to the following and it works as long as I view the lookupCondition2 field and tab out of it.  How can I get this to run without interacting with the field?

$(document).ready(function () {
      $(document).on('blur change', '.lookupCondition2 input', autofill);
  
   function autofill() {
    $('.autofill').trigger('click');
  }   
  $('.lookupCondition2').change(autofill);
});

 

0 0
replied on May 5, 2015

Thanks for the suggestions Li Ma.  After implementing them, I have the situation where the lookup for LookupCondition2 places the values in some of the fields for just a second and then clears them out.  Any suggestions to over come that?

0 0
replied on May 5, 2015 Show version history

Hey Jen:

There may be several reasons that cause the instability of the lookup result:

1. do you bind the lookupCondition2 with other event or field? Or the 'copyfrom' field is binded with other event? If it is, then the behavior may be caused by the calculation order. For example, the website finish the lookup first, but then the field is modified or cleared up by another function.   

2. do you have other lookup rules that involves lookupCondition2? 

3. can you double check the code details such as comma, whitespace, dot and so forth?

If you don't mind, can you post your completed code here and simply describe your lookup rules? Or you can open a support case and upload your business process there, as well as screen shot of the "lookup rules" page and "field rules"  page. It would be easier for me to figure out the reason with completed business process.

0 0
replied on May 4, 2015 Show version history

Hey Jen:

Before solving your problem, there are two optimization suggestions on your code.

1. You don't need to add this line in your UPDATE code:

$(document).on('blur change', '.lookupCondition2 input', autofill);

Instead, you can just change this code line:

$('.lookupCondition2').change(autofill);

into:

$('.lookupCondition2 input').change(autofill);

or:

$('.lookupCondition2 input').on('change blur', autofill);

2. It would be better to trigger the 'change' event not only for 'condition2', but also for 'condition1'. With this code, If you want to make any change in 'condition1' after inputting value into 'condition2', you can still run the autofill function.

$('.lookupCondition1 input, .lookupCondition2 input').change(autofill);

 

For your question, here is the possible solution:

In jQuery, the event 'blur', 'focus' or 'change' are active when you focus on or tab out certain field. Since the event you use to trigger the autofill function is 'blur' or 'change', this function won't be called unless the browser detect focus behavior in the 'lookupCondition2 input' field.  

I am not sure how you copy the 'condition2' field value from another field. If you also implement it with jQuery, then things will be easier.

Suppose the class name of the field where 'condition2' copy value from is: 'copyfrom'.

One possible solution is to attach the 'change' event on the 'copyfrom' field instead of the 'condition2'. Then we can trigger autofill function without focusing on the 'condition2' field.

Here is the suggested code, you can change it according to your use case.

$(document).ready(function () {
  
  function autofill() {
      $('.autofill').trigger('click');
  }   

  $('.lookupCondition1 input, .lookupCondition2 input').change(autofill);

  $('.copyfrom input').on('change', function(){
      //get copy value from the 'copyfrom' field
      var copyValue = $(this).val();
      //set the value of 'condition2' with copy value, and trigger the change event
      $('.lookupCondition2 input').val(copyValue).change();
  })

});

 

Hope the above code can solve your problem. Let me know if you have any questions :)

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

Sign in to reply to this post.