Copied to clipboard

Flag this post as spam?

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


  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 22, 2013 @ 10:38
    Kris Janssen
    0

    Dealing with captions in dynamic .notation

    Say I have a form with a field that has the caption:

    Preferred position (1st choice)

    When trying to get the value of this field using the . notation according to the Contour developer docs it should be accessible as:

    record.Preferredposition1stchoice
    

    i.e. omitting any spaces and non-alphanumerics.

    For some reason however, this does not work? Better to change the caption altogether?

  • Comment author was deleted

    Nov 22, 2013 @ 10:57

    Hmm can you get rid of the 1 so try record.Preferredpositionstchoice

    I'll share the snippet that is used so you have a better idea :)

  • Comment author was deleted

    Nov 22, 2013 @ 10:59

    It's trying to do this

    _record.RecordFields.Where(f => f.Value.Field.Caption.Replace("#", "").Replace(" ", "").ToLower() == name.ToLower())

    so just getting rid of the spaces should do it

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 22, 2013 @ 11:06
    Kris Janssen
    0

    Hi Tim,

    I think I might have a problem then.

    I have captions like these:

    "CV (PDF)" "Preferred Position (1st Choice)"

    () are a problem of course

    In hindsight maybe not the best idea but I'm stuck with it now.

    I'm under the impression that changing the caption also does not yield improvement. So e.g. changing CV (PDF) to CV does not seem to work either.

    I have loads of entries now and I'd still like to display them without losing data :)

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 22, 2013 @ 11:15
    Kris Janssen
    0

    I'm a bit fearful the caption at the time of submitting is stored in the entry, that way, changing a caption afterwards would not result in a solution.

    In any case, changing the caption from "CV (PDF)" to CV in the form designer and next using record.cv still yields an exception... :s

    The binaries could be updated to truly strip out all non-alphanumerics I guess (as stated in the docs).

    Or am I still missing something?

  • Comment author was deleted

    Nov 22, 2013 @ 11:22

    Yup will look at a solution :) that also removes those chars!

    stay tunes solution will arrive today or early next week (and you will lose no data)

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 22, 2013 @ 11:23
    Kris Janssen
    0

    Thanks Tim,

    Would you say that risking a direct edit in the SQL DB would be worth it?

    Cheers,

    Kris

  • Comment author was deleted

    Nov 22, 2013 @ 11:27

    Nah don't do that, I'll just make the dynamic stuff strip out all illegal chars

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 22, 2013 @ 21:34
    Kris Janssen
    0

    Something like

    Regex Cleanregex = new Regex("[^a-zA-Z0-9 -]");
    _record.RecordFields.Where(f => Cleanregex.Replace(f.Value.Field.Caption, "").ToLower() == name.ToLower())
    

    ?

    :)

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 25, 2013 @ 11:28
    Kris Janssen
    0

    Hey Tim,

    Do you have an ETA on a potential hot fix?

    I'd be happy to do some testing if need be.

    If you are awfully busy I might be tempted to do a DB edit anyway.

    Cheers,

    K.

  • Comment author was deleted

    Nov 25, 2013 @ 11:30

    Yup fix will be available today :) eta 15:00

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 25, 2013 @ 11:31
    Kris Janssen
    0

    Perfect!

  • Comment author was deleted

    Nov 25, 2013 @ 13:32

    Fixed, please download the update zip http://nightly.umbraco.org/Umbraco%20Contour/3.0.18%20WIP/ and then just deploy the Umbraco.Forms.Mvc assembly (if you are running 3.0.17)

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 25, 2013 @ 23:51
    Kris Janssen
    0

    Hi Tim;

     

    Did a quick test. The regex used doesn´t filter out the spaces I´m afraid.

    Also, I did a quick reflektor on the modified binary and it seems the regex is instantiated but not used in Trygetmember... in fact, it seems TryGetMember is entirely broken, even for simple captions. It seems the actual selection is never executed:

    _record.RecordFields.Where(f =>Cleanregex.Replace(f.Value.Field.Caption,"").ToLower()== name.ToLower())

    Could it be something was overlooked?

    The regex should be applied and additionally spaces need to be stripped from caption and this should be compared to the supplied name...

    I´m in a bit of a pickle because of this issue :)

     

  • Comment author was deleted

    Nov 26, 2013 @ 08:45

    Ok cool taking another look now

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 26, 2013 @ 15:33
    Kris Janssen
    0

    Hi Tim,

    Anything yet? :)

    Cheers,

    Kris

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 27, 2013 @ 09:04
    Kris Janssen
    0

    Hey Tim,

    As a temporary fix on 3.0.17...

    Would it be safe to edit the values in the column "caption"in dbo.UFFields manually? Or will that destroy the entire coherence of the stored records in some way?

    enter image description here

    On the other hand, is it the case that the dynamic records are somehow deserialized from dbo.UFRecordsXML? Captions seem to be hard-coded there...

    As it stands I have 3 captions with offending characters and people are pushing me to come up with a quick fix so that would buy me some time for a more robust fix in the binaries...

    Cheers,

    Kris

  • Comment author was deleted

    Nov 27, 2013 @ 09:11

    Ah sorry had to do some other stuff yesterday, but as a workaround just fetch it non dynamic , will post a snippet in a minute

  • Comment author was deleted

    Nov 27, 2013 @ 09:12

    yourDynamicRecordobject.RecordFields.Where(f => f.Value.Field.Caption == "YourCaption").First().Value.ValuesAsString()

  • Comment author was deleted

    Nov 27, 2013 @ 09:14

    SO no need to mess with db just use the recordfields to fetch it :) will look into improving the dynamic stuff a bit later today but the snippet should do the trick

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 27, 2013 @ 11:08
    Kris Janssen
    0

    For anyone following this thread, using the non-dynamic approach works. However, since DynamicRecord cannot be cast to Record, the initial collection of records should be retrieved as follows:

    RecordStorage rStor = new RecordStorage();
    @foreach (Record record in rStor.GetAllRecords(new Guid("someguid-as-string"))) 
    

    Whereas before you could use:

    @foreach (dynamic record in Umbraco.Forms.Mvc.DynamicObjects.Library.GetRecordsFromForm("someguid-as-string"))
    

    Otherwise, using a lambda expression as follows will not sit well with the use of dynamic:

    record.RecordFields.Where(f => f.Value.Field.Caption == "First Name").First().Value.ValuesAsString()
    

    Notations are a bit unwieldy so the dynamic route is still preferred/faster...

  • Comment author was deleted

    Nov 27, 2013 @ 12:05

    COol thank for the details, will solve the dynamic stuff this week

  • Kris Janssen 210 posts 569 karma points c-trib
    Dec 02, 2013 @ 08:33
    Kris Janssen
    0

    Hi Tim,

    Are these issues fixed in the newest (.18) version?

  • Kris Janssen 210 posts 569 karma points c-trib
    Dec 17, 2013 @ 07:35
    Kris Janssen
    0

    Hi Tim,

    Were you finally able to roll a fix into the latest release?

  • Kris Janssen 210 posts 569 karma points c-trib
    Feb 25, 2014 @ 16:46
    Kris Janssen
    0

    Hey Tim,

    I don't wish to be annoying but somehow, proper cleanup of dynamic properties on DynamicRecord is still not implemented...

    In my post of November 25, 2013 @ 11:51 I mention that you instantiate a Regex in TryGetMember but you are not actually using it.

    This is still the case in the .19 version of Contour.

    Normally I wouldn't complain too much if this was open source code and I could fix this but this problem is making me have to use ugly workarounds in my code and holding back some of my work. This functionality is in a key part of the code for manipulating records.

    Could you maybe look at getting this patched up? Contour is a paying product after all ;)

    Cheers,

    Kris

  • Kris Janssen 210 posts 569 karma points c-trib
    Feb 28, 2014 @ 07:42
    Kris Janssen
    0

    Any news? 

  • Kris Janssen 210 posts 569 karma points c-trib
    Mar 05, 2014 @ 22:10
    Kris Janssen
    0

    Small bump...  Isn't anybody else seeing this issue pop up???? 

  • Comment author was deleted

    Mar 06, 2014 @ 11:07

    Oops forgot about this one, looking into it now

    btw will I see you at http://umbracobefestival.be/ ?

  • Kris Janssen 210 posts 569 karma points c-trib
    Mar 06, 2014 @ 14:56
    Kris Janssen
    0

    No problem :) Busy times for everyone I think.

    I would love to join for the event in Belgium because I'm thinking of stepping up my web development activities with Umbraco as the foundation but unfortunately I'll be abroad for my day job at that time :(

  • Kris Janssen 210 posts 569 karma points c-trib
    Jun 03, 2014 @ 22:27
    Kris Janssen
    0

    Hello Tim,

    I just checked out Contour .21

    It seems, now, the regex filtering is happening but there is still one remaining oversight: spaces are not filtered from the captions.

    As far as I can tell, the relevant line in TryGetMember(...) is following:

    Regex Cleanregex = new Regex("[^a-zA-Z0-9 -]");
    

    and subsequently:

    Cleanregex.Replace(f.Value.Field.Caption, "").ToLower() == name.ToLower();
    

    I did not check GetMemberBinder (which I think is new) but if I already test these lines in a small test:

    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    
    public class MyClass
    {
    public static void RunSnippet()
    {
        Regex Cleanregex = new Regex("[^a-zA-Z0-9 -]");
        String test1 = Cleanregex.Replace("First Name", "");
        Console.WriteLine(test1);
        String test2 = Cleanregex.Replace("CV (PDF)", "");
        Console.WriteLine(test2);
        String test3 = Cleanregex.Replace("Preferred Choice (1st choice)", "");
        Console.WriteLine(test3);
    }
    
    #region Helper methods
    
    public static void Main()
    {
        try
        {
            RunSnippet();
        }
        catch (Exception e)
        {
            string error = string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString());
            Console.WriteLine(error);
        }
        finally
        {
            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }
    }
    
    private static void WL(object text, params object[] args)
    {
        Console.WriteLine(text.ToString(), args);   
    }
    
    private static void RL()
    {
        Console.ReadLine(); 
    }
    
    private static void Break() 
    {
        System.Diagnostics.Debugger.Break();
    }
    
    #endregion
    

    }

    I get the output:

    First Name

    CV PDF

    Preferred Choice 1st choice

    Press any key to continue...

    I therefore think the regex has a space where it should not (after the 9):

    Regex Cleanregex = new Regex("[^a-zA-Z0-9-]");
    

    This produces the desired output (i.e. strings that can actually be used to access record fields...

    FirstName

    CVPDF

    PreferredChoice1stchoice

    Press any key to continue...

    It would be really great if you could fix this in one of the nightlies...

  • Kris Janssen 210 posts 569 karma points c-trib
    Jun 08, 2014 @ 22:50
    Kris Janssen
    0

    Just a small reminder :)

  • Kris Janssen 210 posts 569 karma points c-trib
    Jun 10, 2014 @ 15:08
    Kris Janssen
    0

    Hi Tim,

    Any news on this? My work relies heavily on being able to handle and display form entries all over my site and the fact that this essential feature has been broken for so long is starting to become a bit bothersome as the size of my website increases.

    Cheers,

    Kris

  • Kris Janssen 210 posts 569 karma points c-trib
    Jun 26, 2014 @ 13:04
    Kris Janssen
    0

    Hello Tim,

    I hate to keep being annoying :), but any chance a fix for CON-558 could be included in a nightly release or something?

    Cheers,

    Kris

  • Paul Fowles 75 posts 184 karma points
    Sep 16, 2014 @ 18:08
    Paul Fowles
    0

    Has this been fixed and can this be added to 3.0.7

Please Sign in or register to post replies

Write your reply to:

Draft