Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • André Lange 108 posts 410 karma points
    Sep 29, 2017 @ 09:25
    André Lange
    0

    Checkboxlist - Get all values available not just set values.

    I want to make a list of tags, which can be chosen from the checkboxlist, so when i create a page, i can then select which tags is associated to the page.

    But i also want to be able to display all available tags in the list, which is created in that datatype "checkboxlist", so not just the ones that have been chosen.

    It is so i can display them on a page, so i can search with the tags.

    But how can i manage this ?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 29, 2017 @ 13:05
    Alex Skrypnyk
    1

    Hi Andre

    You can get all prevalues of datatype with this code:

    var dataType = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionByName("My Datatype Name");
    var preValuesFromDataType = library.GetPreValues(dataType.Id);
    

    Thanks,

    Alex

  • André Lange 108 posts 410 karma points
    Oct 02, 2017 @ 06:12
    André Lange
    0

    i added your code to my controller, but when i try to write it out in my view, through my model, with this:

    @foreach (var item in Model.AllTags.)
        {
              <td><a href="#">@item</a></td>
        }
    

    It says item is an object ? and it doesn't appear to hold any of the values i have added.

    code from my controller:

    var dataType = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionByName("tags");
                var preValuesFromDataType = library.GetPreValues(dataType.Id);
    
                model.AllTags = preValuesFromDataType;
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 02, 2017 @ 07:08
    Alex Skrypnyk
    100

    Hi Andre

    Try this code:

    @{
        var dataType = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionByName("tags");
        var preValues = ApplicationContext.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).PreValuesAsDictionary.Select(x => x.Value).ToList();
    
        var allTags = preValues;
    }
    @foreach (var item in allTags)
    {
        <td><a href="@item.Value">@item.Value</a></td>
    }
    
  • André Lange 108 posts 410 karma points
    Oct 02, 2017 @ 08:04
    André Lange
    0

    I tried your new code, but all i get is a "default" value, and nothing else.

    In umbraco it looks like this:

    This is in umbraco

    but all it writes out are "default".

  • André Lange 108 posts 410 karma points
    Oct 02, 2017 @ 08:33
    André Lange
    0

    I only get a "default" value, and nothing else.

    Checkbox in umbraco backend

    on the image you can see the values i have saved in the "tags" datatype.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 02, 2017 @ 08:34
    Alex Skrypnyk
    0

    What did you mean default value?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 02, 2017 @ 08:34
    Alex Skrypnyk
    0

    Check please here - .GetDataTypeDefinitionByName("tags");

    tags - it should be the name of your datatype

  • André Lange 108 posts 410 karma points
    Oct 02, 2017 @ 08:53
    André Lange
    0

    Datatype setup:

    This is the datatype And the doctype setup: Doctype setup

    So i should write "Article Tags" instead of tags ?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 02, 2017 @ 08:53
    Alex Skrypnyk
    1

    Andre, yes

  • André Lange 108 posts 410 karma points
    Oct 02, 2017 @ 09:05
    André Lange
    0

    Awesome :D That worked !

    i am so sorry for missing that one.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Oct 02, 2017 @ 09:05
    Alex Skrypnyk
    0

    Glad to help you, have a nice day!

Please Sign in or register to post replies

Write your reply to:

Draft