Change function in lookup is triggered two times - bug?

Hey all,

I've got a strange problem which might be a bug - I've also cleared cache / cookies and so on, but the problem still exists:

I have two lists - one is a calendar event list and one is a normal list which has a lookup to the title of the event in the calendar list. The lookup fields name is "Veranstaltung".

In the calendar I have a field "Zusatzangabe Text".

What I want to do is following:

  • user selects an event from the filtered lookup
  • if Zusatzangabe_x0020_Text in the event list is not empty, then the field "Zusatzangabe" should be shown
  • else the field should be hidden

What happens is the following (can also be seen in the gif below)

  • if I select an event in the lookup which has text in "Zusatzangabe_x0020_Text" then the on change function is triggered two times and the selection is deselected - even If I only have the "alert" in the function and everything else commented out
  • if I select an event in the lookup which hasn't got any text in "Zusatzangabe_x0020_Text" then the on change function is triggered one time

Relevant code:

localStorage.clear();
fd.spRendered(function() {
        var dateTimeToday = new Date().toISOString()
        fd.field('Veranstaltung').filter = "geschlossen eq'" + false + "' and EndDate ge'" + dateTimeToday +"'";
        fd.field('Veranstaltung').orderBy = {field: 'EventDate', desc: false};
        fd.field('Veranstaltung').refresh();
});
fd.spRendered(function() {
    fd.field('Veranstaltung').ready().then(function(){
            fd.field('Veranstaltung').$on('change', showAdditionalContent);
            function showAdditionalContent(){
                alert("change");
                if(fd.field('Veranstaltung').value.Zusatzangabe_x0020_Text !== null)
                {
                        console.log("not null");
                        $(fd.field('Zusatzangabe').$parent.$el).show();
                }
                else
                {
                        console.log("null");
                        $(fd.field('Zusatzangabe').$parent.$el).hide();
                }
            };
    });
});


Is this a bug or is my code rubbish? Because it seems to work but the on change is triggered twice - and I can't explain why.

Just fiddled around a little bit more and tried it with pnpJS - the same issue happens again. The onchange function seems to be triggered a second time as soon as I click outside of the lookup field.

Code used for this reproduction:

fd.spRendered(function() {

    fd.field('Veranstaltung').ready().then(function(){

            fd.field('Veranstaltung').$on('change', showAdditionalContent);

            function showAdditionalContent(){

                pnp.sp.web.lists.getByTitle("Veranstaltungskalender").items.filter("ID eq " + fd.field('Veranstaltung').value.ID +"'").get().then(function(items) {

                    console.log(fd.field('Veranstaltung').value.ID);

                    var AdditionalText = items[0].Zusatzangabe_x0020_Text;

                    var AdditionalNecessary = items[0].Zusatzangabe_x0020_notwendig;

                    console.log(AdditionalText);

                    console.log(AdditionalNecessary);

                    console.log(items[0]);

                    if(AdditionalNecessary = true && AdditionalText != null)

                    {

                            console.log("not null");

                            $(fd.field('Zusatzangabe').$parent.$el).show();

                            fd.field('Zusatzangabe').required = true;

                            fd.field('Zusatzangabe').title = fd.field('Veranstaltung').value.Zusatzangabe_x0020_Text;

                    }

                    else

                    {

                            console.log("null");

                            $(fd.field('Zusatzangabe').$parent.$el).hide();

                            fd.field('Zusatzangabe').required = false;

                    }

                });   

            };

    });

});

Sorry for the spam. But I just discovered the following: the three events that are shown with ID 26, 28 and 29 were created before I added "Zusatzangabe notwendig" and "Zusatzangabe text" to the calendar list.
These seem to be working correctly but every event I created after that has the above problem. Even when i comment out the on change function, the value doesn't stay the same after I click out of the Lookup Field. This seems to be the issue but I can't explain why :frowning:

Hello @JonHebbe,

I couldn't reproduce the issue on my form.

What SharePoint version are you using: Online or On-premises?

What is the version of the desktop designer? You can find it in the top left of the screen.

If you are using the online version, what is the version of the app package?

You can find the app package version in the browser console (F12) >> Sources >> Page >> forms.plumsal.com
image

The latest app package version is 1.0.8. If the app package version is outdated, please follow the steps from the instructions to get the latest version:
Update the app package for Plumsail Forms (SharePoint Online) — SharePoint forms

Hey, I'm on Sharepoint 2019 Server, so On-Prem.
The desktop designer version is 1.4.8.

Hello @JonHebbe,

Does the same behavior occur in other lists? Please try to reproduce the issue in a different form with the lookup field pointing to another list.

Hey @mnikitina,
I just rebuilt the entire calendar and now it works as expected.

Really strange and annoying issue, don't know what exactly happened but now it works as I wanted.

Thank you for your help.

1 Like