pnp / List-Formatting

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

I have question about FAQ Accordion style #549

Closed Vishni92 closed 2 years ago

Vishni92 commented 2 years ago

faq-accordion

How to disable the 'ShowMore' button when that text filed is empty? I want to display the 'ShowMore' button only if there are any contents. If there are no contents, disable the button.

aaclage commented 2 years ago

you just need to add condition that [$Answer] has content to button appear.

{
              "elmType": "button",
              "customRowAction": {
                "action": "defaultClick"
              },
              "txtContent": "Show more",
              "attributes": {
                "class": "sp-row-button"
              },
              "style": {
                "display": "=if([$ShowMore] == 'Yes' &&  indexOf([$Answer]+';',';')>-1, 'block', 'none')",
                "margin-bottom": "8px",
                "color": "white",
                "background-color": "#0077DB"
              }
            }
Vishni92 commented 2 years ago

@aaclage

Thank you for your response. I try your code and it doesn't work well. That code also apply all the items

aaclage commented 2 years ago

sn't work well. That code also apply all the items

Forgot to remove the validation [$ShowMore] == 'Yes', should only appear if has text.

Vishni92 commented 2 years ago

=if([$ShowMore] == 'Yes' && indexOf([$Answer]+';',';')>-1, 'block', 'none')

If I add [$ShowMore] == 'Yes', it didn't appear any 'ShowMore' button even if text isn't empty. When I add as =if([$ShowMore] == '' && indexOf([$Answer]+';',';')>-1, 'block', 'none') it will appear 'ShowMore' button every item.

aaclage commented 2 years ago

I meant

=if(indexOf([$Answer]+';',';')>0, 'block', 'none')
Vishni92 commented 2 years ago

tempsnip I use first item to add ShowMore contentes, but every item has that button when items are no contents in ShowMore.

=if(indexOf([$Answer]+';',';')>0, 'block', 'none') this is same result

aaclage commented 2 years ago

there is alway a answer with content the button will appear, what field should validate?

Vishni92 commented 2 years ago

Yes, there is always Answer and some Answers has ShowMore filed contents. Some items have ShowMore details and some items hasn't.

aaclage commented 2 years ago

ok ok now i understand the correct fields should be [$ShowMore]

=if(indexOf([$ShowMore]+';',';')>0, 'block', 'none')
Vishni92 commented 2 years ago

It works for once and when I refreshed the page it didn't appear ShowMore button in any. I am so confusing

aaclage commented 2 years ago

try to close all tabs and give a look in the formating if the condition continues there.

Vishni92 commented 2 years ago

I change the browser and clear browser data. But I it didn't work. I have no idea what happened. But once it worked.