Guys, quick question to save me time. I never work with datasets, but I made a quick faq with a dataset. The collection holds, you guessed it, a question and an answer field. In the answer, I want to have a URL (like <a href=…).
It looks like that field is thrown towards the .text property of a text-element, not towards its .html-property, so the <a href does not show a link, it just shows, in text, <a href …>
Is there some hidden dataset/repeater setting where I can choose the text element’s .html property or do I do it in code?
Hi there my fellow Master,
If you’re using a dataset, the only way to do it is to have it done through the repeater’s onItemReady handler, and not through the dataset.
$w('faqRep').onItemReady(($item, data) => {
$item('#answer').html = `<a href="${data.link}">${data.answer}</a>`;
})
You can customize how it looks as you want too, and I don’t need to mention that this needs to be placed before the dataset is ready (the top scope inside the page’s onReady function).
Hope this helps my friend.
Ahmad
Thanks Ahmed, that’s what I thought. Will do. Bit awkward, still: a text element has 2 properties you can use to throw content at (.text and .html), but using a dataset, the choice is limited to 1, the .text. I never use datasets and this is another reason: too limited at times.
May I ask why you didn’t use a rich text field to hyperlink your answer instead of a text field?
Love,
CQ
The reason for that is that datasets were originally created for those who don’t know how to code to help them build more powerful websites, which is the same reason why they think they won’t probably need the html property, or even how to use it anyway.
Hi Nayelli, long time no hear. The answer is: ignorance. Most of my work is backend. RTB did not come to mind, I thought it had that word processor interface. But I saw you can set it to float and then it seems to disappear. But …, the min height is 100px and that is too high for me. Thanks for the idea, abrazo.
EDIT:just re-read your answer. Now think you are referring to the collection’s rich text field, not the rich text box. Dunno, will try.
Dear Nayelli, looks like you were right. When I asked “Is there some hidden dataset/repeater setting”, turns out this is it. Seems like:
- if a collection text field is linked to a text element, it is thrown towards the .text property
- if a collection Rich text field is linked to a text element, it is thrown towards the .html property
Cost me more time then doing it in code, but I learned something. And, I finally could click my way out of something. Owe you one.
Lol …
My brain breaks things down a different way than most developers. Sorry I didn’t specify “field in the database collection”. A screenshot would have probably saved you more extra time.
Have a good one. Talk soon.
@code-queen My dear Code Queen, pray tell, is there a way to specify in the (rich text field’s) link ‘target=“_blank”’? For now, the link is loaded in the same page, which I do not want, I want the link to open in a new tab.
EDIT : tried (in rich text field) click here, but that displays the whole above link (but working, it opens a new tab, but very ugly). Good mind going back to code.