Copied to clipboard

Flag this post as spam?

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


  • Kenny Burns 173 posts 305 karma points
    Jun 01, 2013 @ 17:54
    Kenny Burns
    0

    Dropdown Prevalues

    Hi,

    I am currently using contour 3.0.12 and I am setting up some forms code first (nice work by the way! Totally awesome stuff!)

    I am trying to put some prevalues into a dropdown:

      [Field(FormPages.RegistrationBusiness, FormFieldsets.BusinessDetails,
              Type = typeof(DropDownList), Prevalues=new string[]{"Sole Trader", "Limited Company"}, 
              Mandatory = true)]
            public string BusinessType { get; set; }

    ...But I would like those prevalues to come from an umbraoco datatype if that is possible - if not is there a way to have prevalues have both a value and text?

    Hope that makes sense!

    Cheers -

    Kenny

  • Comment author was deleted

    Jun 03, 2013 @ 11:36

    Hey Kenny,

    Yeah for that you'll need to set a prevalue source so instead of setting the Prevalues set PrevalueSource 

    You can also create prevalue sources from code 

    As an example this creates one of the type UmbracoPrevaluesReadOnly (that uses datatype prevalues) of the datatype with id 1234

      [PrevalueSource("From umbraco")]

        public class CustomPrevalueSource: PrevalueSourceBase

        {

     

            public override Umbraco.Forms.Core.FieldPreValueSourceType Type

            {

                get 

                {

                    var prevalueSource = new Umbraco.Forms.Core.Providers.Prevalues.UmbracoPrevaluesReadOnly();

                    prevalueSource.DataTypeId = "1234";

                    return prevalueSource;

                }

            }

        }

     

    Then on your form field set  PrevalueSource = "From umbraco" (so use prevalue source name)

  • Kenny Burns 173 posts 305 karma points
    Jun 04, 2013 @ 22:08
    Kenny Burns
    0

    Hi Tim,

    Thanks for that - this works a treat. Is there a way though that i can have the value of the source as the dropdown option value (its just using the string)?
    (does that make sense??! - see images below)

    I also was wondering if its possible to have a form that you can edit another users profile (i.e. http://www.nibble.be/?p=205 - Profile form but somehow have the default value come from a member you have loaded in from a querystring or something.)

    Sorry for all the questions!! I'm really enjoying the code first stuff though! :)

    Many thanks

    K

     

  • Comment author was deleted

    Jun 05, 2013 @ 10:41

    Well I guess you could just update the view for that fieldtype to use the value instead of the text 

    For the member edit, you can set defaults from querystring/session/cookie so maybe that could be usefull?

  • Kenny Burns 173 posts 305 karma points
    Jun 05, 2013 @ 11:46
    Kenny Burns
    0

    Ahhh! Yeah - i knew it would be something as easy as that (dropwdown) - perfect Tim.

    Yeah that would work - (members) - do you have an example of this anywhere?

    Thanks mate - really helpful! :)

  • Comment author was deleted

    Jun 05, 2013 @ 11:54

    Yeah just set the default value to:

    Insert page value: [#propertyAlias]

    Insert recursive page value: [$propertyAlias]

    Insert cookie value or session: [%cookieValue]

    Insert value from request collection: [@requestKey]

     

  • Comment author was deleted

    Jun 05, 2013 @ 11:56

    So would look like

     [Field("Profile", FormFieldsets.Details,

               Mandatory = true,

                DefaultValue = " [@requestKey]")]

            public string Name { get; set; }

  • Kenny Burns 173 posts 305 karma points
    Jun 05, 2013 @ 12:16
    Kenny Burns
    0

    Thats great Tim - thanks a lot. Will check that out tonight and let you know how I get on.

    Cheers,

    Kenny

Please Sign in or register to post replies

Write your reply to:

Draft