Customize lookup template with address field

Hey,

I'm trying to figure out how to integrate a SharePoint address field into the template of a lookup field.

I added Address to Extra Fields on the LookupField. And tried a few ways to access the data.

    template += '<div> #: data.Adress  #</div>';
    template += '<div > #: data.Adress:City #</div>';
    template += '<div > #: data.Adress.City #</div>';

Just using data.Adress renders a object. But the object seems to be just a string when i look up the value like this fd.field('').value.Address.

Best wishes,
Nico

Dear Nico,
Yes, it's a bit tricky to work with the Address field. The following should do the trick:

var template = '#: data.LookupValue # - #: JSON.parse(data.FieldName).Address.Street # - #: JSON.parse(data.FieldName).Address.City #';

Thank you. This works fine if i access the data like this:
JSON.parse(fd.field('').value.Adresse).Address.Street

Using this code in the template:
#: JSON.parse(data.Adresse).Address.Street #

The dropdown doesn't open and there is no error in the console. Some of the values are null, is this a problem?

Dear Nico,
Shouldn't be an issue, they'll just be empty. Can you share all of your code for setting the template?

I simplifed it a bit.

FieldName = Addresse

Doens't work, with no error:

var test = '<span class="test-col">#: JSON.parse(data.Adresse).Address.Street #</span>';
fd.field('Bauwerk').widgetOptions = {
        template: test,
        height: 440,
        virtual: {itemHeight: 55 },
        dataSource: {pageSize: 32}
} 

This works and shows the whole object as string:

var test = '<span class="test-col">#: data.Adresse #</span>';
fd.field('Bauwerk').widgetOptions = {
        template: test,
        height: 440,
        virtual: {itemHeight: 55 },
        dataSource: {pageSize: 32}
} 

This shows: object object
#: JSON.parse(data.Adresse) #

This shows the street in the console:
JSON.parse(fd.field('Bauwerk').value.Adresse).Address.Street

Dear Nico,
That's strange, are you sure you're using the latest version of the App Package? Also, which browser are you trying it in?

I have the following code on my form (just copied and pasted):

And here's the result that I get on the form:
image

Good Morning @Nikita_Kurguzov,

App Package version is 1.0.8.0

I created an empty form and tried in IE(no cached files), FF and Chrome. Still the same problem.

I checked the network activity in the browsers console, clicking on the field sends out an Odata request, which gets answered with the right data. But the dropdown doesn't open.

I'll be on vacation the next week, maybe the problem solves itself until then, if not I will reach out again.

Dear Nico,
Please, try to update the package to the latest version 1.0.8.1, then clear the cache and try again - Update the app package for Plumsail Forms (SharePoint Online) — SharePoint forms

I finally got around to solve the problem.

The issue is that Sharepoint address fields have different EntityTypes(PostalAddress, Custom) depending on that the Address data is stored differently. Also, some addresses were empty or only partly filled.

This shows the street if there is one and won't break the lookup field if there is none.

#: data.Adresse !== null ? JSON.parse(data.Adresse).Address !== undefined ? JSON.parse(data.Adresse).Address.Street ?? "no street" : "undefined" : "no address" #
1 Like