I am trying to have pages dynamically generated from one database link to pages dynamically generated from other databases. Basically:
I have a fiction database with fields “title” and “text,” and reference fields “author” and “issue number.” I also have an author database with the field “author,” and an issue database with the field “issue number.”
I can generate a list of all fiction entries with “title” and “text” from the database, and I can call in the “name” and “issue number” from the other databases, but I can’t make those text boxes clickable to link to the individual stories, author pages, or issue pages.
My work-around was to turn those fields into buttons instead of text boxes because they are set up to pull a label and a url, and that finally worked but now I have the problem that the text boxes won’t change size depending on the length of the text in the given field. (E.g., a title renders as “This is the title of…” instead of “This is the title of the story.”)
How do I make the buttons change size depending on the text pulled from the databases? Or, alternatively, how do I keep them as text boxes (which seem to change size automatically) and still link them to the appropriate dynamically-generated pages?
An example of the problem is here: https://theleon0226.wixsite.com/usf-v3/fiction
I’ve tried to find a solution in what has already been asked, but I didn’t come up with anything. Thank you, anyone, who might have some insights on this problem!
1 Like
I still don’t know about the reflow issue for the button text, but I’ve made partial progress on the other prong, connecting urls to textboxes.
The progress:
I added a URL field to my main database for author and issue, and inserted this code:
import wixLocation from ‘wix-location’ ;
$w.onReady( function () {
$w( ‘#listRepeater’ ).onItemReady((selector, itemData, index) => {
$w( ‘#text16’ ).onClick(() => {
wixLocation.to(itemData.issuelink);
});
$w( ‘#text14’ ).onClick(() => {
wixLocation.to(itemData.authorlink);
});
});
});
This is a step in the right direction in that it creates a link, but each item on the list links to the same page (the url field of the database’s oldest entry instead of the url field for each item). My assumption is that wixLocation is defining issuelink before it cycles through the database to generate the items in the list, but I’m not sure how to fix it.
Hi Leon
Use the regular button, it’ll change its width based on the button’s label.
Hey Ahmad, thanks for your answer. I am using a regular button as far as I can tell. The text that generates is longer than the width. The goal is for the text to go to a second line. (Like a textbox would.)
Unfortunately, that’s not possible with buttons, however, what you can do is using a text element and use onClick() function to redirect the visitors to the relevant link when it’s clicked.
That’s fair, and I’ve implemented an onClick() function, but each item pulls the url from the oldest database entry instead of the url listed for each item. An example is here with Issue One and Issue Two: https://theleon0226.wixsite.com/usf-v3/poetry
Each item in the database has a unique url (which is the same as what’s generated dynamically in the issues database), but they all pull the url only from Issue Two. Any idea why? The code I am using is given above.
Thanks for your help!
Okay, I dug through some old questions and found a solution. I couldn’t get the reflow to work on the buttons, so I changed them back to text boxes and inserted the following code:
import wixLocation from ‘wix-location’ ;
$w.onReady( function () {
let baseURL = wixLocation.baseUrl;
$w( “#listRepeater” ).onItemReady(($item, itemData, index) => {
const repeatedTitle = $item( “#text14” );
repeatedTitle.onClick ((Event) => {
wixLocation.to(baseURL + itemData[ “link-fiction-title” ])
})
const repeatedName = $item( “#text15” );
repeatedName.onClick ((Event) => {
wixLocation.to(itemData[ “authorLink” ])
})
const repeatedIssue = $item( “#text16” );
repeatedIssue.onClick ((Event) => {
wixLocation.to(itemData[ “issueLink” ])
})
})
})
Where:
listRepeater is the name of my repeater,
#text14 is the name of my title box,
“link-fiction-title” is the dynamically generated post URL,
#text15 is my author box,
“authorLink” is the field key of the author URL in my fiction database (couldn’t connect it directly to the author database because I’m calling the author name as a reference field in my fiction database),
#text16 is my issue box, and
“issueLink” is the field key of the issue URL (for the same reason)
If anybody else has the same problem, I hope this helps.
References:
- https://www.wix-blog-community.com/blog/discussions/is-this-possible
- https://www.wix.com/corvid/forum/community-discussion/resolved-referencing-dynamic-page-url-in-wixlocation