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

Question

Question

Reapply Default Drop-Down Value to Lookup Rule After allowClear:true

asked on May 6, 2021 Show version history

Hello,

I'm a .Net Developer coming into Laserfiche as a complete newbie looking to modify an already existing issue in a Laserfiche form.

The form contains a single line (id = q1) and based upon the value entered in this single line it selects that value (via lookup rule) within a dropdown list (id = q2) that is populated from a data source.

Before an entry is input in q1, q2 behaves as intended. The form opens with q2 being populated via the data source. I can select an entry, clear it and the data source is maintained to select other entries.

As soon as I enter a value in q1 that serves at the lookup for the dropdown (q2), the dropdown is updated with only the value from the q1. When I clear the dropdown of its q1 value, the dropdown is empty.

I need to be able to repopulate the dropdown (q2) with the original data source if the equivalent value from q1 is cleared within the dropdown (q2) - yet keep the value entered in q1.

This can be acheived fairly simply in a asp.net page due to written logic and taking advantage of the change event in the postback.

I need to somehow mimick that either revising the lookup rule and/or via css & javascript.

Does anyone have any suggestions or can you please point me in the right direction?

Function to apply the select2 follows:

function ApplySelect2() {
      $.getScript(' ', function () {
            $('.q2 select').select2({
            width: "450px",
            placeholder: "Select an employee",
            allowClear: true
            });
        });      
      
       }

Thank you in advance for your assistance.

0 0

Replies

replied on May 7, 2021 Show version history

Well this is exciting, I found this function that triggers the lookup rule you're after:

LF.lookup.prePopulate($('.q2 select'));

It does throw a TypeError: this.changeAndTrigger is not a function, but it populates the dropdown with the initial lookup results.

0 0
replied on May 10, 2021

Nice! I'll give this a try. I'll post back if I can get it to work. Thank you for your assistance. 

0 0
replied on May 10, 2021

May I ask where you inserted it to work?

I nested it inside the ApplySelect2 function (after the .getScript function closed - disables lookup function) and then put inside the getScript function once that didn't work and behavior is same as without the line of code.

I'll continue to investigate.

Thank you

0 0
replied on May 10, 2021 Show version history

I tested it by listening to q1's change event and running the function if the value is blank:

$(function () {
    $('q1 input').change(function () {
        if (!this.value) {
            LF.lookup.prePopulate($('q2 select'));
        }
    })
})

I hadn't heard of select2 until I saw this post so if there's a good way to integrate the function call in there, I don't know about it.

0 0
replied on May 10, 2021

Awesome. I'll take a look at this asap. Thank you for your assistance!!

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

Sign in to reply to this post.