Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Constrained Textbox Element Form Element for EPiserver
.epi-forms-icon.epi-forms-constrainedtextboxelementblock__icon {
background-image: url(constrainedtextboxelementblock16x16.png);
}
<%@ import namespace="System.Web.Mvc" %>
<%@ import namespace="EPiServer.Web.Mvc.Html" %>
<%@ import namespace="EPiServer.Forms.Core.Models" %>
<%@ import namespace="EPiServer.Forms.Implementation.Elements" %>
<%@ control language="C#" inherits="ViewUserControl<$rootnamespace$.Business.Forms.ConstrainedTextbox.Block.ConstrainedTextboxElementBlock>" %>
<% var formElement = Model.FormElement;
var labelText = Model.Label;
var maxLength = Model.MaxLength;
%>
<div class="Form__Element FormTextbox" data-epiforms-element-name="<%: formElement.Code %>" >
<label for="<%: formElement.Guid %>" class="Form__Element__Caption"><%: labelText %></label>
<input name="<%: formElement.Code %>" id="<%: formElement.Guid %>" type="text" class="FormTextbox__Input"
placeholder="<%: Model.PlaceHolder %>" value="<%: Model.PredefinedValue %>" <%: Html.Raw(formElement.AttributesString) %>
maxlength="<%: maxLength %>" />
<span data-epiforms-linked-name="<%: formElement.Code %>" class="Form__Element__ValidationError" style="display: none;">*</span>
</div>
using System.ComponentModel.DataAnnotations;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Forms.Implementation.Elements;
namespace $rootnamespace$.Business.Forms.ConstrainedTextbox.Block
{
[ContentType(
DisplayName = "Constrained Textbox",
GroupName = "Form Elements",
GUID = "5445D5A7-965F-45FF-BF49-5633B83F2ECF")]
public class ConstrainedTextboxElementBlock : TextboxElementBlock
{
[Display(
GroupName = "Forms authoring",
Order = 1,
Name = "Max field length",
Description = "The maximum length of the input field"),
CultureSpecific]
public virtual int MaxLength { get; set; }
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
MaxLength = 10;
}
}
}
using EPiServer.Forms.EditView;
using EPiServer.Shell;
using $rootnamespace$.Business.Forms.ConstrainedTextbox.Block;
namespace $rootnamespace$.Business.Forms.ConstrainedTextbox.UIDescriptor
{
[UIDescriptorRegistration]
public class ConstrainedTextboxElementBlockDescriptor : FormElementBlockDescriptor<ConstrainedTextboxElementBlock>
{
}
}
<?xml version="1.0" encoding="utf-8" ?>
<languages>
<language name="English" id="en">
<contenttypes>
<constrainedtextboxelementblock>
<name>Constrained Textbox</name>
</constrainedtextboxelementblock>
</contenttypes>
</language>
</languages>
<?xml version="1.0" encoding="utf-8"?>
<module>
<clientResources>
<add name="Forms" path="~/Business/Forms/ConstrainedTextbox/ClientResources/ConstrainedTextbox.css" resourceType="Style" />
</clientResources>
</module>
@davidknipe

This comment has been minimized.

Copy link
Owner Author

davidknipe commented Jan 6, 2016

This is the icon that is associated
constrainedtextboxelementblock16x16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.