Copied to clipboard

Flag this post as spam?

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


  • Damon 217 posts 288 karma points
    Jul 13, 2017 @ 08:46
    Damon
    0

    Forms - is there a postcode lookup field for address?

    Hi,

    we want to add a field for postcode that will auto show s the addresses that the user can choose.

    Is there anything in Umbraco Forms that does this?

    Thanks!

  • zell 37 posts 90 karma points
    Jul 26, 2017 @ 02:19
    zell
    0

    no, but you can create your own.
    you need to create a new fieldtype based on the textfield field type, like this:

    public class AddressTextField : FieldType
    {
        public AddressTextField()
        {
            //Provider 
            this.Id = new Guid("d8d89001-57ce-4b52-9005-c0c84f6651cb");
            this.Name = "Validated address field";
            this.Description = "Renders an text input field, for short answers"; //FieldType 
            this.Icon = "icon-autofill";
            this.DataType = FieldDataType.String;
            this.SortOrder = 13;
            this.SupportsRegex = true;
            this.FieldTypeViewName = "FieldType.AddressTextField.cshtml";
            this.Category = "Custom";
        }
    }
    

    copy the field type views for Textfield and rename them as FieldType.AddressTextField.cshtml (views/forms/themes/default/fieldtypes) etc.

    there are a number of views you need to add to make your own custom fieldtype, these are in the following locations:

    • App_Plugins\UmbracoForms\Backoffice\Common\FieldTypes
    • Views\Partials\Forms\Themes\default\Fieldtypes
    • Views\Partials\Forms\Fieldtypes

    but add an additional class property to the input field which you can use in a piece with something like https://twitter.github.io/typeahead.js/examples/ or similar.

    see documentation here: https://our.umbraco.org/documentation/Add-ons/UmbracoForms/Developer/Extending/Adding-a-Fieldtype.

    note: you'll need to install umbraco forms from nuget to access umbraco.forms.core

Please Sign in or register to post replies

Write your reply to:

Draft