pnp / List-Formatting

List Formatting Samples for use in SharePoint and Microsoft Lists
https://pnp.github.io/List-Formatting/
MIT License
1.76k stars 846 forks source link

faq-keyword-links-format.json has made me sad, please help #332

Open garnern2 opened 3 years ago

garnern2 commented 3 years ago

Sample (which sample are you having trouble with)

faq-keyword-links-format.json

What Should Happen

From the documentation, I believe I should enter a keyword in the Keyword column: test and link in the KeywordLink column: http://www.google.com . When I use the word " test " anywhere in the Answer column, it should create a link with the KeywordLink URL " http://www.google.com "

What Actually Happens

The keyword " test " is simply a plaintext word with no hyperlink in any view.

wiredwisk commented 3 years ago

There are two sets of code provided. One with the keyword function and one without. Make sure you are using the correct one. However, I've noticed when you use the keyword code there is an error were extra text shows up at the end of the answer. I fixed it with the code below: { "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json", "hideListHeader": true, "hideSelection": true, "rowFormatter": { "elmType": "div", "style": { "display": "flex", "flex-direction": "column", "align-items": "flex-start" }, "children": [ { "elmType": "div", "attributes": { "class": "ms-bgColor-themePrimary ms-borderColor-themeDark ms-fontColor-white" }, "style": { "font-size": "22px", "border-width": "2px", "border-style": "solid", "width": "95%", "padding": "4px" }, "children": [ { "elmType": "span", "txtContent": "Q", "attributes": { "class": "ms-fontColor-themeTertiary" }, "style": { "padding-right": "10px", "padding-left": "6px", "font-weight": "bold" } }, { "elmType": "span", "txtContent": "[$Title]" } ] }, { "elmType": "div", "attributes": { "class": "ms-borderColor-themeDark" }, "style": { "padding-left": "40px", "width": "95%", "border-width": "2px", "border-style": "solid", "padding": "4px", "font-size": "16px", "border-top-width": "0", "margin-bottom": "20px" }, "children": [ { "elmType": "span", "txtContent": "[$Answer]", "style": { "display": "=if(length([$Keyword]) && length([$KeywordLink]),'none','')" } }, { "elmType": "div", "style": { "display": "=if(length([$Keyword]) && length([$KeywordLink]),'','none')" }, "children": [ { "elmType": "span", "txtContent": "=substring([$Answer],0,indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))" }, { "elmType": "a", "style": { "display": "=if(indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword])) != -1, '', 'none')", "font-weight": "bold" }, "attributes": { "class": "ms-fontColor-themeSecondary", "href": "[$KeywordLink]", "title": "[$KeywordLink.desc]" }, "txtContent": "=substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword])),indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'))" }, { "elmType": "span", "style": { "display": "=if(indexOf(substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'),1000)+'|','|') < indexOf([$Answer]+'|','|'), '', 'none')" }, "txtContent": "=substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'),if(indexOf(toLowerCase(substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'),1000)),toLowerCase([$Keyword])) == -1, 1000, indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|') + indexOf(toLowerCase(substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'),1000)),toLowerCase([$Keyword]))))" }, { "elmType": "a", "style": { "display": "=if(indexOf(toLowerCase(substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'),1000)),toLowerCase([$Keyword])) != -1, '', 'none')", "font-weight": "bold" }, "attributes": { "class": "ms-fontColor-themeSecondary", "href": "[$KeywordLink]", "title": "[$KeywordLink.desc]" }, "txtContent": "=substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|')+indexOf(toLowerCase(substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'),1000)),toLowerCase([$Keyword])),indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|')+indexOf(toLowerCase(substring([$Answer],indexOf(toLowerCase([$Answer]),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'),1000)),toLowerCase([$Keyword]))+indexOf([$Keyword]+'|','|'))" } ] } ] } ] } }