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
    Nov 20, 2013 @ 16:00
    Kenny Burns
    0

    Code First - Field Additional Settings

    Hey,

    I am builidng a contour form using code first approach (great by the way!) and was wondering how I would go about getting additional settings or parameters into the view for each field? Like addtional CSS styles or anything else I might want to access in the view. I tried AdditionalSettings but that is returning nothing in the view.

    Any ideas?

    Thanks,

    Kenny

    example:

    [Field(FormPages.Enquiry, FormFieldsets.Details, Caption = "Website Address", Mandatory = false, AdditionalSettings = new[] { "param1", "param2" })]
    public string WebsiteAddress { get; set; }
  • Comment author was deleted

    Nov 20, 2013 @ 16:14

    Take a look at the recaptcha view that has an example :)

  • Comment author was deleted

    Nov 20, 2013 @ 16:15

    So that has the example Model.AdditionalSettings.FirstOrDefault(x => x.Key == "Theme").Value

  • Kenny Burns 173 posts 305 karma points
    Nov 20, 2013 @ 16:24
    Kenny Burns
    0

    I am using it like below in a view - but AdditionalSettings is always returning nothing. I think I must be missing something. Should AdditionalSettings be Key Value Pairs?

     

    foreach (FieldsetViewModel fs in Model.CurrentPage.Fieldsets)

    {

     @foreach (FieldViewModel f in fs.Fields)

    {

    if (f.AdditionalSettings.Count > 0)

    {

    //do something


    }

    }

  • Comment author was deleted

    Nov 20, 2013 @ 16:31

    will check captcha code to see how it's handled :)

  • Comment author was deleted

    Nov 20, 2013 @ 16:51

    The fieldtype also needs the extra setting :) maybe that is missing

  • Comment author was deleted

    Nov 20, 2013 @ 16:52

    so in case of the recaptcha one it has a setting

    [Setting("Theme", prevalues = "red,white,blackglass,clean,custom", description = "ReCaptcha theme", control = "Umbraco.Forms.Core.FieldSetting.Dropdownlist")] public string Theme { get; set; }

  • Comment author was deleted

    Nov 20, 2013 @ 16:54

    so since you aren't setting the type it's just a textfield and that doesn't have any additional settings

  • Kenny Burns 173 posts 305 karma points
    Nov 20, 2013 @ 17:57
    Kenny Burns
    0

    Okay - so how would we go about adding additional settings to a textfield? If for example we wanted to add an additional HTML attribute to each textfield? Would we have to create our own field type/field attribute/field view model so we could pass the class into the view?

    Sorry - have been going round in circles! 

  • Comment author was deleted

    Nov 20, 2013 @ 18:04

    New fieldtype :) probably inherit from textfield and add the extra setting + make sure to update the guid

  • Steve 140 posts 321 karma points
    Dec 03, 2015 @ 21:45
    Steve
    0

    Hi Tim,
    Would it be possible to give an example of how to do this in Forms? I'd like to make a custom field type which displays text on the form but does not submit anything to the entries table. Just can't seem to figure out how to exclude the field from the submission process...
    Thanks, Steve

  • Kenny Burns 173 posts 305 karma points
    Nov 20, 2013 @ 18:45
    Kenny Burns
    0

    Thanks for all your help Tim - i think this is what we were after.

    Cheers! :)

Please Sign in or register to post replies

Write your reply to:

Draft