I s there a way to create elements (like buttons) with code ?
I try to dynamically create download buttons for documents stored on wix and in my CMS collection in different fields. I work with dynamic pages and each line (element) correspond to a published page. In those pages, I would like to automatically create a download button for each of multiples documents, which are stored as fields (columns) in the CMS collection. The purpose is to not have to pre-create those buttons and the hide those for wich the field is empty, but actually create them only if the field isn’t empty. (the issue with the first option is that I have a large number of document fields and only a few of them are actually containing a document, so when I hide the buttons corresponding to empty fields, it produce a very high empty space.
in wich columnStrip5 is the element in which I would like to create the buttons, planRdc and edl23PlanRdc are two documents fields which I know they contain a document (but like I said I have like 30 of it to check).
It did not work.
Your code looks quite complex whereas this is pretty much what you want from your description I think:
Obviously change the elements involved as you need them but this principle should work for your needs!
Just remember Show/Hide = the space on your page will be the same regardless, either content or empty space, the button is still there but hidden.
Collapse/Expand = the space taken by the element will disappear when collapsed and this is what you are using in your current code, so it should work as long as you’ve set the space of the site where the buttons are (section, container, repeaters etc) to be “auto” or a “max/min” (so they’ll adjust with the collapse/expand) and that depends on your page design. Otherwise you’ve told that space to be “x height” regardless of the content inside it. You can also set your element to be collapsed in the editor as mentioned in the linked answer rather than coding it to be collapsed.
Hopefully that’ll get you on your way to a nice solution!
Thanks for your answer.
Actually, I don’t want to use hide or collapse on an pre-existing element (which I was until now, but as I said it produce an emty space on the page, I didn’t find any height option in the editor to be set to auto or min/max or fit-content …). I try to build the elements (buttons) from scratch if the fields are not empty …
If you coded or set your button to not show on your live page this example container would still show empty space because it’s minimum height is 280px.
If it was set to auto it would collapse entirely. When the button is expanded and visible on the live page the container would wrap around the button like so.
If your proposed method worked rather than the one you are currently using it wouldn’t make a difference if the height of the container housing the button has a pre-set height, that seems to be your issue here not any of the coding or complex stuff, seemingly just a design issue.
I’m using Editor X in those examples but it’s there for Studio and old Wix too, might look slightly different depending on the platform. It’s the inspector panel on the right side of the page and you will need to click an element first to show it’s (Layout) sizing properties. I know Studio is set to some terrible new defaults for adjusting sizes of things so you have to click something else in that panel to revert it back to the way mine looks, I can’t remember off the top of my head what the settings are called on there, it’s really frustrating to have to do that for every new object on your whole site, lol… but if you are using the older editors it should look like mine anyway as soon as you create a container, button or whatever!
I haven’t used the classic editor in ages, I can’t see any equivalent options there either, lol… it really is fundamental stuff as you say, I’d switch over to either Editor X or Studio if I was you, I really forgot how limited the original editor was for that kind of thing!
You might have a bit of a learning curve getting used to the newer editors quirks but it’s totally worth it for actual control over your page design! Also Editor X and Studio are practically the same, just slightly different placement of things mostly so you can go for either and you’ll be futureproofed either way without as much hassle as the change from the original Wix Editor.
Yep and Wix Studio is brand new (so missing some features at the moment, but some things are improved from Editor X of course). You should be able to migrate your site to at least X… I haven’t kept up to date with what the deal is with Studio other than making fresh sites with it, but I’m sure there are articles here if you search for “migrate from Wix Editor” or something similar!
(Perhaps make a copy of your site if you do migrate just in case you don’t get on with it)