Copied to clipboard

Flag this post as spam?

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


  • Chris Foot 4 posts 95 karma points
    Jul 13, 2017 @ 13:44
    Chris Foot
    1

    Ordering fields from a form record

    I am currently trying to develop a front-end for viewing entries to one of the forms in our umbraco forms system. Unfortunately, I can't seem to work out how to get the fields ordered the same way as they are in the front end. I've got the following code:

         @{
     var record = Library.GetApprovedRecordsFromForm(formId).Items.First(x => x.Id == recordId);
    }
    
            @foreach (var recordField in record.RecordFields)
            {
                <div class="input-group contour">
                    <label class="input-group-label">@recordField.Value.Field.Caption</label>
                    <input type="text" disabled="disabled" class="input-group-field input-group-display" value="@recordField.Value.ValuesAsString(false)" />
    
                </div>            
            }
    

    This does produce output but it seems to sort in a completely random order. I've seen examples using .OrderBy(r => r.Value.Field.PageIndex) but this property no longer seems to exist!

    Can anyone offer any suggestions as to how to get this working?

    Thanks

    Chris

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Jul 13, 2017 @ 16:14
    Alex Skrypnyk
    1

    Hi Chris

    It looks like it's a bug:

    http://issues.umbraco.org/issue/CON-878

    Thanks,

    Alex

  • Chris Foot 4 posts 95 karma points
    Jul 13, 2017 @ 16:19
    Chris Foot
    0

    Ahh, open since February too, guess it's not going to be fixed any time soon! Oh well...

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Jul 13, 2017 @ 16:25
    Alex Skrypnyk
    0

    By the way, maybe Umbraco Forms 6 hasn't this bug?

    What version are you using?

  • Chris Foot 4 posts 95 karma points
    Jul 14, 2017 @ 08:38
    Chris Foot
    100

    Hi Alex,

    Good catch, i'm not on 6! I just installed it yesterday through the forms page in the backend so assumed I had the latest version but we're on umbraco 7.5.x so only got the v4 of forms! Looks like i've got some upgrading to do!

    Thanks for your help

    Chris

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Jul 14, 2017 @ 08:39
    Alex Skrypnyk
    0

    You are welcome, Chris. Have a great weekend.

    Thanks,

    Alex

  • Chris Foot 4 posts 95 karma points
    Jul 18, 2017 @ 09:10
    Chris Foot
    0

    Nope, still an issue in 6. It still brings them back in a random order. It wouldn't be a problem if they were in the same order as in the backend!

  • Aaron Yarborough 2 posts 75 karma points
    Jul 24, 2018 @ 13:39
    Aaron Yarborough
    3

    I was experiencing this issue running Umbraco Forms 6.0.8. I managed to work around it however after finding out that calling the GetForm() message on an instance of Form will return the fields in the correct order.

    Annoyingly, the field instances under Form.AllFIelds don't hold values for their Values property so you still have to use RecordStorage to get the values.

    This is what I ended up writing:

    public static IEnumerable<RecordField> GetRecordValues(Guid recordUniqueId)
    {
        using (var formStorage = new FormStorage())
        using (var recordStorage = new RecordStorage())
        {
            var record = recordStorage.GetRecordByUniqueId(recordUniqueId);
            var form = record.GetForm();
    
            var orderList = form.AllFields.Select(x => x.Alias).ToList();
            return record.RecordFields.Select(x => x.Value)
                .OrderBy(x =>orderList.IndexOf(x.Alias));
        }
    }
    

    Hope this helps!

  • Nurhak Kaya 53 posts 147 karma points MVP 2x c-trib
    Nov 02, 2020 @ 21:29
    Nurhak Kaya
    0

    Nice one Aaron, you have helped me! Thanks. #h5yr

  • John Dawson 24 posts 135 karma points
    May 18, 2021 @ 11:08
    John Dawson
    0

    Been having this issue myself and just found this thread. Will try Aaron's solution, but is this a bug that hasn't been fixed since 2017?

Please Sign in or register to post replies

Write your reply to:

Draft