I'm having trouble with the Expand/Not Expand. I've followed instruction from the Vendor rating template but still no luck..
What I've done :
- Creating an paper accordion widget (not cards) named AccordionServeur with this script in the
onDataLoad
event :
var rows = widget.children._values;
for (var i = 0; i < rows.length; i++) {
if (rows[i].name.indexOf('AccordionServeurDetail') === -1) {
rows[i].styles = ['collapsed'];
}
}
Add some TextBox inside the AccordionServeurRow to edit the value (i.e. with datalink)
Create the client script with this code:
function expandAccordionRow(accordionRow) {
var rows = accordionRow.parent.children._values;
var i = 0;
for (i = 0; i < rows.length; i++) {
if (rows[i].name.indexOf('AccordionServeurDetail') > -1) {
rows[i].styles = [];
} else {
rows[i].styles = ['collapsed'];
}
}
accordionRow.styles = [];
}
function collapseAccordionRow(accordionRow) {
var rows = accordionRow.parent.children._values;
var i = 0;
accordionRow.styles = ['collapsed'];
for (i = 0; i < rows.length; i++) {
if (rows[i].name.indexOf('AccordionServeurDetail') > -1) {
rows[i].styles = ['hidden'];
}
}
}
function toggleAccordionRow(accordionRow) {
if (accordionRow.styles.length === 0) {
collapseAccordionRow(accordionRow);
} else {
expandAccordionRow(accordionRow);
}
}
- On the AccordionServeurRow, in the
onAttach
event, I run this script:
widget.styles = ['collapsed'];
widget.getElement().removeAttribute('aria-expanded');
- On the AccordionServeurRow, in the
onClick
event, I run this script:
toggleAccordionRow(widget);
- On the AccordionServeurDetail, in the
dataLoad
event, I run this script:
widget.styles=['hidden'];
But it still expands the detail when I open the page where the widget is. Plus the detail stays expanded event if I click on the AccordionRow. Did I miss something in the script or is it because of parameters in the widget ?
EDIT : I've found the solution. You have to create style "collapsed" and to call them in the script above :
.app-AccordionRow.collapsed {
margin: 0 !important;
}
.app-AccordionDetail.hidden {
display: none !important;
}