Forum
Can a divider be told to show initially as collapsed ?
Is there a way to tell a divider (divider-before, divider-after) to initially show as collapsed. So the content in the divider is hidden.
edit:
I have written a script to handle this, it is on GitHub:
https://github.com/rlb222/Perch-Auto-collapsable-Dividers
edit-end
My use-case is: I want to offer the editor of the content three content fields to fill. There is a heading, a text area and one optional image field.
Because the image field is not often used and takes a lot of space in the interface, I would very much like to hide it, until being used. This makes recognizing the content on the page much easier. I am showing multiple items on an edit page.
- Can the dividers be told to collapse initially?
- Could I program a field type to do this, is this advisable ?
- Am I going at this the wrong way maybe, and is there a better, more Perch like solution?
thks! René
This has been suggested many times. I would love to be able to do this with something like
collapse-divider="true"
. Until then, in this thread, Robert shows his way of accomplishing what you're after (5 posts down).Thank you! I had never thought of using the ui possibility and using javascript.
I'm trying it out, and wanted to make use of the code from Perch that is already there. But have not yet succeeded in doing it the way I would like to do it. Traversing the Dom is giving me problems.
So maybe I will end up having to copy the code from Robert, but i that case Perch is doing the same thing twice. I will update this thread when I have a solution.
René
This is my solution now
I have altered the code from Robert, to reflect the current default behaviour of Perch.
I have three remarks with this:
(edit: below is a version without a timer)
thx, René
The template file looks like this
Thanks René
Where are you placing your JS?
The JavaScript is in This file.
‘/perch/addons/plugins/ui/_config.inc’ Just add the file. No extra setings needed.
René
I have made a new version without the timer, and with an external script which will watch for the creation of the needed element.
That's a great post René - thanks for providing that.
We found that to use your same code in a multiple instance situation, we needed to make the following changes. The reason being, it used the first divider name for all subsequent dividers:
Thanks very much for finding and fixing this bug! In your code you left out making the end-dividers invisible, maybe you didn't need it.
The new and complete version is on GitHub: https://github.com/rlb222/Perch-Auto-collapsable-Dividers
Thx, René