Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » Tagfield returns tag string inside a <a> tag with javascript?

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 733 Views
  • DsX
    Avatar
    Community Member
    178 Posts

    Tagfield returns tag string inside a <a> tag with javascript? Link to this post

    I am using the tagfield as a field in a nested DOM (I have a page with imageResources that have imageDetails).
    In the backend everything is good. Tagfield works, everything save, no errors anywhere. DataModel appears to be good.

    In the templates, I return a imageResource from a getter that looks it up by ID, I can them control thru imageDetails and I can display my 3 elements (Role, URL, Name)
    Role is a enum, and URL and Name both use tagfield.
    If I only wish to display the Role, everything is great.
    When I try to out either $URL or $Name, I get something like:

    <ul id="Menu1">
    <li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">FirstName </a></li>
    <li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">LastName</a></li>
    </ul>

    The text in the anchor in the List item is the text I expect, the rest of the HTML/javascript not.
    In the case above there are 2 list items, this is because when entering the Name it gave me 2 tags in the tag field, where I would Ideally see "FirstName LastName".
    URL is returning the same, but with a single List item.

    Looking at the table in the database I see that the stored data is the simple Varchar strings. eg: 'FirstName'

    So is there a way to get the clean string data eg: 'FirstName LastName' returned in my control?

  • DsX
    Avatar
    Community Member
    178 Posts

    Re: Tagfield returns tag string inside a <a> tag with javascript? Link to this post

    Solved it..

    can't believe this stumped me for so long ;)

    You need to control through the associated Tagfields inside the context of the class that contains them.

    I think that fact that I was getting something was messing with me, at first I though it was being created live by Javascript..

    anyway, as a side effect I see how to create a list of associated tags like a tag cloud, however I do not know how to set the URL for the links??

    any additional help would be great.

    733 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.