Unable to displayed the custom form field?

Vote:
 

Hi Guys,

       As per requirement i want to create my own form field,but when i drag and drop field its not displayed here is my code

namespace EpiserverSite5.Models.Blocks
{
  [ContentType(DisplayName = "CustomTextBoxElementBlock", GUID = "c5230b6e-7da0-4400-942c-0f33b6f801b6", Description = "")]
  public class CustomTextBoxElementBlock : TextboxElementBlock
  {
   [Display(
   Name = "Max length",
   Description = "The maximum number of characters.",
   Order = 2999)]
   public virtual int? MaxLength { get; set; }

  }
}

CustomTextBoxElementBlock.cshtml

@model EpiserverSite5.Models.Blocks.CustomTextBoxElementBlock
@using System.Web.Mvc
@using EPiServer.Forms.Helpers.Internal
@using EPiServer.Forms.Implementation.Elements
@using EPiServer.Forms.EditView.Internal
@using EPiServer.ServiceLocation

@{
    var errorMessage = Model.GetErrorMessage();
    var errorStyle = string.IsNullOrEmpty(errorMessage) ? " display:none" : string.Empty;
    var validationService = ServiceLocator.Current.GetInstance();
  }
     


       data-f-element-name="@Model.FormElement.ElementName" data_f_type="textbox">
     
     
      id="@Model.FormElement.Guid"
     type="text"
      class="FormTextbox FormTextbox__Input @Model.FormElement"
     placeholder="@Model.PlaceHolder"
    value="@Model.GetDefaultValue()"
    @Html.Raw(Model.AttributesString) />
     
     class="Form__Element__ValidationError"
    style="@errorStyle">@errorMessage

    @Model.RenderDataList()

When i drag form fied into form container,i get this  error

Error:

The  'CustomTextBoxElementBlock' can not  be displayed

Can any one help me out of this.

Thanks,

Kartheek

#187109
Jan 12, 2018 6:14
Vote:
 

Kartheek,

Can you tell us which Epi version you are using?  Also, are you using the new Forms add-on (the one documented on this page:https://world.episerver.com/documentation/developer-guides/forms/)?

#187134
Jan 12, 2018 16:47
Vote:
 

Hi Kartheek 

I wrote about creating a custom form field for Episerver Forms here:

https://www.david-tec.com/2016/01/building-out-a-custom-form-element-with-the-new-episerver-forms/

Let me know if it helps.

David 

#187135
Jan 12, 2018 17:27
Vote:
 

Hi David,

    i have already gone through the link,but the example is not working as expected.can you suggest any other referance.

Thanks,

Kartheek

#187261
Jan 17, 2018 7:14
Vote:
 

Hey, Kartheek,

I have an email element block. It is built as an Add-On, but you could take it for inspiration.

Btw, where did you place your cshtml? 

BR,
Marija

#187265
Jan 17, 2018 10:36
Vote:
 

Hi Marija Jemuovic,

       Thanks for your time consideration of this matter,i placed my .cshtml in Shared-->blocks-->Myview.cshtml.

Thanks,

Kartheek.

#187267
Jan 17, 2018 11:08
Vote:
 

Hey,

Does it work if you move it to Views / Shared / ElementBlocks?

BR,
Marija

#187271
Jan 17, 2018 14:06
Vote:
 

Thanks Marija Jemuovic,

   

     Your reference email block element is helpfull for creating textbox.

Thanks,

Kartheek.

#187365
Jan 22, 2018 6:14
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.