Copied to clipboard

Flag this post as spam?

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


  • Glenn Franquet 15 posts 46 karma points
    Aug 07, 2015 @ 09:46
    Glenn Franquet
    0

    How to use Multiple Textbox

    I have a datatype using the property editor Multiple Textbox. I use this in Grid Editors created with LeBlender and in the admin it's working fine. But I have an issue to display the values of the different textboxes in the frontend.

    The code I use is:

    @if (Model.Items.Any())
    {
        <ul>
            @foreach (var item in Model.Items)
            {
                var advantages = item.GetValue("advantage");
    
                foreach (var vid in advantages)
                { 
                            <li>@vid</li>
                } 
            }
        </ul>
    }
    

    The output I get is a list with in every li one character of System.String[]

    <ul>
                            <li>S</li>
                            <li>y</li>
                            <li>s</li>
                            <li>t</li>
                            <li>e</li>
                            <li>m</li>
                            <li>.</li>
                            <li>S</li>
                            <li>t</li>
                            <li>r</li>
                            <li>i</li>
                            <li>n</li>
                            <li>g</li>
                            <li>[</li>
                            <li>]</li>
        </ul>
    

    I tried some things to get the correct result but I only got a variation on the display of System.String[]. So I'm a little bit clue less for the moment.

    Is it possible to use Multiple Textbox in combination with LeBlender? If yes, how can I get the value of every textbox?

  • Steve Morgan 1022 posts 3185 karma points c-trib
    Aug 07, 2015 @ 11:26
    Steve Morgan
    0

    Not used LeBlender but does this work?:

    var advantages = item.GetPropertyValue

    Failing that - are you running Visual Studio - stick a breakpoint on that line and inspect advantages.

  • Steve Morgan 1022 posts 3185 karma points c-trib
    Aug 07, 2015 @ 11:27
    Steve Morgan
    0

    Hmm... that line should be (without the spaces before and after String[]:

    var advantages = item.GetPropertyValue< String[] >("advantage");

    The forum formatting code seems to have changed it.

  • Glenn Franquet 15 posts 46 karma points
    Aug 07, 2015 @ 11:38
    Glenn Franquet
    0

    GetPropertyValue doesn't work in this case.
    item is in my example code from the type LeBlenderValue so a specific type from LeBlender.

    I can pass also the type when using the GetValue function of LeBlender. If I use item.GetValue< String[] >("advantage"); (also without the spaces before and after String[] ;-)) than the result is.

    <ul>
                            <li>[</li>
                            <li></li>
                            <li>  {</li>
                            <li></li>
                            <li>    &quot;value&quot;: &quot;Item 1&quot;</li>
                            <li></li>
                            <li>  },</li>
                            <li></li>
                            <li>  {</li>
                            <li></li>
                            <li>    &quot;value&quot;: &quot;Item 2&quot;</li>
                            <li></li>
                            <li>  },</li>
                            <li></li>
                            <li>  {</li>
                            <li></li>
                            <li>    &quot;value&quot;: &quot;Item 3&quot;</li>
                            <li></li>
                            <li>  },</li>
                            <li></li>
                            <li>  {</li>
                            <li></li>
                            <li>    &quot;value&quot;: &quot;Item 4&quot;</li>
                            <li></li>
                            <li>  }</li>
                            <li></li>
                            <li>]</li>
        </ul>
    

    So I think that the trick is to find the good type to pass but I don't have any idea what I could use.

  • Steve Morgan 1022 posts 3185 karma points c-trib
    Aug 07, 2015 @ 14:09
    Steve Morgan
    0

    HI,

    Had a quick look at this. Not sure what the Lecoati foreach does but... you just need to GetValue

    e.g. I created three mutli text strings called "text1", "text2", "text3" and this outputs all of my strings.

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    @foreach(var item in Model​.​Items​)
    { 
        <ul>
            <li>@(item.GetValue<string>("text1"))</li>
            <li>@(item.GetValue<string>("text2"))</li>
            <li>@(item.GetValue<string>("text3"))</li>
        </ul>
    }
    

    Hope that helps.

  • Glenn Franquet 15 posts 46 karma points
    Aug 07, 2015 @ 14:21
    Glenn Franquet
    0

    Thanks Steve but I'm afraid that your solution will not work.

    I'm using the property editor Multiple Textbox (new in Umbraco 7)
    Maybe this is so new that LeBlender not yet support this.

    This means that there is a single document type "advantage" in my example. That can contain dynamically multiple values (one for every textbox the content editor can add). That's the reason why I try to use the second for each.

    If I don't get it working than I will probably switch to a normal text string. The content editor can add than also multiple textboxes but I had the feeling that this was a little bit more user-friendly with Multiple Textbox.

  • Steve Morgan 1022 posts 3185 karma points c-trib
    Aug 07, 2015 @ 14:59
    Steve Morgan
    0

    Sorry - I'd never seen that Multi Textbox datatype before!

    The (incomplete) documentation suggests that it should return a string array.

    It actually returns a JArray... so this should work.

    @inherits UmbracoViewPage

    var advantageArrayStrings = advantageArray.Select(x => (string)x["value"]);
    if (advantageArrayStrings.Count() > 0)
    {
        <ul>
            @foreach (var curAdvantage in advantageArrayStrings)
            {
            <li>@curAdvantage</li>
            }
        </ul>
    }
    

    }

  • Steve Morgan 1022 posts 3185 karma points c-trib
    Aug 07, 2015 @ 15:00
    Steve Morgan
    100

    GRRR

    The forum is stuffing the code again.

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    @foreach (var item in Model.Items)
    {
        var advantageArray = item.GetValue<Newtonsoft.Json.Linq.JArray>("advantage");
    
        var advantageArrayStrings = advantageArray.Select(x => (string)x["value"]);
        if (advantageArrayStrings.Count() > 0)
        {
            <ul>
                @foreach (var curAdvantage in advantageArrayStrings)
                {
                <li>@curAdvantage</li>
                }
            </ul>
        }
    }
    
  • Glenn Franquet 15 posts 46 karma points
    Aug 07, 2015 @ 15:13
    Glenn Franquet
    0

    Thanks Steve! You are my hero of the day :-) It's indeed working when using the Newtonsoft.Json.Linq.JArray

    It is possible that when we use the Multiple Textbox as a 'normal' document type that it will be indeed a string array. But that LeBlender did a convert to JArray. Anyway I have now a nice li list with the values of the Multiple Textbox in my grid.

  • Steve Morgan 1022 posts 3185 karma points c-trib
    Aug 07, 2015 @ 15:18
    Steve Morgan
    0

    No problem - glad to be of help!

  • Anders Brohus 159 posts 397 karma points
    Jan 06, 2016 @ 09:51
    Anders Brohus
    0

    Sorry for taking this topic up again but, thanks Steve! :-)

    I got the same problem but your solution worked! :-)

Please Sign in or register to post replies

Write your reply to:

Draft