Copied to clipboard

Flag this post as spam?

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


  • J 445 posts 862 karma points
    Jun 14, 2013 @ 16:35
    J
    0

    Access control in code

    I have a class which builds a form. I would like to access a dropdown list and take relevant action depending on the selection

    [Field(FormPages.Registration, FormFieldsets.Details, Type = typeof(DropDownList), Caption=@"Select Country", Prevalues= new string[] {"USA", "Germany", "UK"}, Mandatory = true)]

    How could i access the above control in code to get the selectedvalue?

    Thanks

  • Comment author was deleted

    Jun 14, 2013 @ 16:47

    Hey look at the examples here you can just override the submit method and then access the properties and they should be filled with the chosen values on submit

    http://www.nibble.be/?p=205

  • J 445 posts 862 karma points
    Jun 17, 2013 @ 15:49
    J
    0

    Thanks but when i used that code as a guide it seems the control is comparing the GUID against the value im testing against and not the text value displayed i.e

    if (Country == "Germany") ......

    then its reading it as

    if (Country == 2cc3c8e-fd4g-491d-8374-755446c0c4dd)

    How could i compare against the text value?

  • Comment author was deleted

    Jun 17, 2013 @ 15:52

    You could fetch it from the prevalue storage or another way would be to update the dropdownlist view so it uses the text as value

  • J 445 posts 862 karma points
    Jun 17, 2013 @ 16:27
    J
    0

    How would i update the dropdown list so it uses a text value?

  • Comment author was deleted

    Jun 17, 2013 @ 16:28
  • J 445 posts 862 karma points
    Jun 17, 2013 @ 16:48
    J
    0

    Thanks for that but im using Contour 1.1.12 so dont think that link would apply?

    So i looked into getting the prevalue storage values and im not sure where to start from as ive seen multiple different code samples?

  • Comment author was deleted

    Jun 17, 2013 @ 16:54

    Are you sure you are on 1.1.12 since code first isn't in that (only from version 3 and up)

    Sure take a look at Umbraco.Forms.Data.Storage.PrevalueSourceStorage

  • J 445 posts 862 karma points
    Jun 17, 2013 @ 17:00
    J
    0

    Yes it definately 1.1.12. I found that code and used it as a guide.... could be the reason why im getting the odd behaviour? To get the prevalues im using this thread as a guide - should this be ok or would i find different issues down the line?

    http://our.umbraco.org/forum/umbraco-pro/contour/12438-Getting-prevalues-through-the-API

  • Comment author was deleted

    Jun 17, 2013 @ 17:00

    Yeah should still work

  • J 445 posts 862 karma points
    Jun 17, 2013 @ 17:29
    J
    0

    theres no GetAllPreValues method and GetPrevalueSource accepts a GUID but i am trying to pass in the Country i.e.

    [Field(FormPages.Registration, FormFieldsets.Details, Type = typeof(DropDownList), Caption=@"Select Country", Prevalues= new string[] {"USA", "Germany", "UK"}, Mandatory = true)]

    public string Country {get; set;} 

                Umbraco.Forms.Data.Storage.PrevalueSourceStorage preStor = new Umbraco.Forms.Data.Storage.PrevalueSourceStorage();

                List<Umbraco.Forms.Data.Storage.PrevalueSourceStorage> p = preStor.GetPrevalueSource(****);

  • J 445 posts 862 karma points
    Jun 18, 2013 @ 15:47
    J
    0

    Just realsied that the namespace should be Umbraco.Forms.Data.Storage.PreValueStorage.

    This has me along the right track but if my code is 

    [Field(FormPages.Registration, FormFieldsets.Details, Type = typeof(DropDownList), DefaultValue = "{member.Country}", Caption=@"Select Country", Prevalues= new string[] {"USA", "Germany", "UK"}, Mandatory = true)]

    public string Country {get; set;} 

    What is a field? In other word what am i passing into GetAllPreValues();

  • J 445 posts 862 karma points
    Jun 19, 2013 @ 11:54
    J
    0

    Using this code it still doesnt work - Any ideas? Anyone? I generated a GUID and passed it in manually so not sure if thats causing an issue?

                using (Umbraco.Forms.Data.Storage.PreValueStorage pvs = new Umbraco.Forms.Data.Storage.PreValueStorage())
                {
                    var val = pvs.GetPreValue(new Guid("C81C77EE-0ACC-4561-8AFB-6E402CD4694E")).Value;
    
    
                    if (val == "USA")
                    {
  • Comment author was deleted

    Jun 19, 2013 @ 12:00

    Hey you don't need to generate a new guid, simply pass it in the guid you get 

     2cc3c8e-fd4g-491d-8374-755446c0c4dd in your example

  • Comment author was deleted

    Jun 19, 2013 @ 12:01

    if (Country == "Germany") ......

    then its reading it as

    if (Country == 2cc3c8e-fd4g-491d-8374-755446c0c4dd)

    So pass in Country :) and it should get you the value

  • J 445 posts 862 karma points
    Jun 19, 2013 @ 12:26
    J
    0

    Ok still getting some unusual results :(.

    First heres the code incase i am doing something wrong 

            [Field(FormPages.Registration, FormFieldsets.Details, Type = typeof(DropDownList), DefaultValue = "{member.Country}", Caption = @"Select Country", Prevalues = new string[] { "USA""Germany""UK" }, Mandatory = true)]
    
            public string Country { getset; } 
    using (Umbraco.Forms.Data.Storage.PreValueStorage pvs = new Umbraco.Forms.Data.Storage.PreValueStorage())             {                 var val = pvs.GetPreValue(new Guid("2cc3c8e-fd4g-491d-8374-755446c0c4dd")).Value;                 if (Country == "USA")                 {

    That code is generated on my local machine. I then copy the dll to the app_code directory for the site.

    The GUIDS are different to the one above?

  • Comment author was deleted

    Jun 19, 2013 @ 12:32

    Could you try

    var val = pvs.GetPreValue(newGuid(Country)).Value
    if val == "USA
  • J 445 posts 862 karma points
    Jun 19, 2013 @ 12:43
    J
    0

    That seems to have worked - whoo hoo!!!! 

    Ill go through a full test and if any probs will reply back. Thanks again for your help.

  • Comment author was deleted

    Jun 19, 2013 @ 12:44

    Sweet glad I could help :)

Please Sign in or register to post replies

Write your reply to:

Draft