Nov 06, 2012, 5:13 PM
Pressing enter in a textarea submits the form
When enter is pressed in the Notes field, the form is submitted. What have I done that it is not inserting a new line?
_Layout.cshtml
_Layout.cshtml
@using Ext.Net.MVC<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site_ext.css")" rel="stylesheet" type="text/css" />
</head>
<body>
@Html.X().ResourceManager().IDMode(IDMode.Static)
@(@Html.X().Viewport().Layout(LayoutType.Fit).Add(
@Html.X().Panel().Layout(LayoutType.Border).Items(i =>
{
i.Add(
Html.X().Panel()
.BodyStyle("background-color: #5c87b2; padding: 1px;")
.Border(false)
.BodyBorder(0)
.Region(Region.North)
.Height(100)
.Split(false)
.ContentFromPage(this, "_Header.cshtml"));
i.Add(
Html.X().Panel()
.BodyPadding(5)
.Layout(LayoutType.Fit)
.Border(false)
.BodyBorder(0)
.Region(Region.Center)
.Split(false)
.ItemsFromSection(this, "body", true));
})
))
</body>
</html>
Partial Code@model Admin.Models.dbo.Customer@using Admin.CRM
@using Admin.Models.dbo
@using Admin.Util
@using ExtensionMethods = Admin.Util.ExtensionMethods
<script type="text/javascript">
var populateForm = function (combo, records, eOpts) {
var data = records[0].data;
App.CompanyName.setValue(data.CompanyName);
App.Addr1.setValue(data.Street1);
App.Addr2.setValue(data.Street2);
App.Addr3.setValue(data.City);
App.Addr4.setValue(data.State);
App.PostCode.setValue(data.PostalCode);
App.Phone1.setValue(data.Phone1);
};
</script>
@{
var isCreate = ViewContext.RouteData.Values["action"].ToString() == "Create";
}
@(
@Html.X().Panel().Border(false).Items(pi => pi.Add(
@Html.X().FormPanel().ID("FPl")
.StandardSubmit(true)
.Title((isCreate ? "Create" : "Edit") + " Company")
.Layout("Column")
.MaxWidth(1000)
.BodyPadding(5)
.AutoHeight(true)
.Buttons(b =>
{
var txt = isCreate ? "Create Company" : "Save";
var save = new Button { Text = txt, FormBind = true };
save.Listeners.Click.Handler = "App.FPl.submit();";
b.Add(save);
})
.Items(i =>
{
var leftPanel = new Panel { Layout = "AnchorLayout", ColumnWidth = 0.7, Border = false };
var rightPanel = new Panel { Layout = "AnchorLayout", ColumnWidth = 0.3, Border = false };
var defaultsLeft = new ParameterCollection { new Parameter("LabelWidth", "200"), new Parameter("LabelAlign", "right"), new Parameter("Anchor", "100%") };
var defaultsRight = new ParameterCollection { new Parameter("LabelWidth", "150"), new Parameter("LabelAlign", "right"), new Parameter("Anchor", "100%") };
leftPanel.Defaults.AddRange(defaultsLeft);
rightPanel.Defaults.AddRange(defaultsRight);
var companyName = @Html.X().ComboBox()
.DisplayField("CompanyName")
.ValueField("InfusionSoftCompanyId")
.FieldLabel("Pull data from InfusionSoft")
.HideBaseTrigger(true)
.EmptyText("Find company in InfusionSoft")
.ID("InfusionSoftCompanyId")
.Triggers(t => t.Add(new FieldTrigger { Icon = TriggerIcon.Clear, Qtip = "Clear" }))
.Listeners(l => l.TriggerClick.Handler = "this.removeByValue(this.getValue());this.clearValue();")
.MinChars(1)
.Store(s =>
{
var store = new Store { AutoLoad = false };
var proxy = new AjaxProxy { Url = "/webservices/InfusionSoft/FindCompany.ashx" };
var reader = new JsonReader { Root = "companies", TotalProperty = "total" };
proxy.ActionMethods.Read = HttpMethod.POST;
proxy.Reader.Add(reader);
var model = new Model();
typeof(Company).GetPropertyList().ForEach(p => model.Fields.Add(p));
store.Proxy.Add(proxy);
store.Model.Add(model);
s.Add(store);
})
.QueryMode(DataLoadMode.Remote)
.QueryDelay(500)
.Listeners(l => { l.Select.Fn = "populateForm"; });
var country = @Html.X().ComboBox()
.ID("CountryId")
.FieldLabel("Country")
.DisplayField("Code")
.ValueField("CountryId")
.AllowBlank(false)
.ToolTips(tt=>tt.Add(new ToolTip{ Html= "Important - Creates either UK or IRL categories" }))
.Store(s =>
{
var store = new Store { };
s.Add(store);
var model = new Model { };
store.Model.Add(model);
model.Fields.Add("CountryId");
model.Fields.Add("Code");
store.DataSource = ViewBag.Countries;
store.DataBind();
});
leftPanel.Items.AddRange(new AbstractComponent[]
{
companyName,
new Label {Html = " "},
ExtensionMethods.SetV(new TextField {ID = "CompanyName", FieldLabel = "Company Name", AllowBlank = false}, ViewContext, Model, model => model.CompanyName),
ExtensionMethods.SetV(country, ViewContext, Model, model => model.CountryId),
ExtensionMethods.SetV(new TextField {ID = "Addr1", FieldLabel = "Addr1"}, ViewContext, Model, model => model.Addr1),
ExtensionMethods.SetV(new TextField {ID = "Addr2", FieldLabel = "Addr2"}, ViewContext, Model, model => model.Addr2),
ExtensionMethods.SetV(new TextField {ID = "Addr3", FieldLabel = "Addr3"}, ViewContext, Model, model => model.Addr3),
ExtensionMethods.SetV(new TextField {ID = "Addr4", FieldLabel = "Addr4"}, ViewContext, Model, model => model.Addr4),
ExtensionMethods.SetV(new TextField {ID = "PostCode", FieldLabel = "Post Code"}, ViewContext, Model, model => model.PostCode),
ExtensionMethods.SetV(new TextField {ID = "Phone1", FieldLabel = "Phone 1"}, ViewContext, Model, model => model.Phone1),
ExtensionMethods.SetV(new TextArea {ID = "Notes", FieldLabel = "Notes", Height = 200, AutoHeight = true}, ViewContext, Model, model => model.Notes),
});
if (isCreate)
{
rightPanel.Items.AddRange(new AbstractComponent[]
{
new DisplayField {FieldLabel = "AutoRec Credits", Text = "This will be available after you create the company."},
});
}
else
{
rightPanel.Items.AddRange(new AbstractComponent[]
{
new TextField {ID = "AvailableCredits", FieldLabel = "Available Credits", Value = Model.CustomerCredit.AvailableCredits},
new DisplayField {FieldLabel = "Total Credits Used", Text = Model.CustomerCredit.TotalCreditsUsed.ToString()},
new DisplayField {FieldLabel = "Total Pages Used", Text = Model.CustomerCredit.TotalPagesUsed.ToString()},
new Hidden {ID = "CustomerId", Value = Model.CustomerId},
});
}
i.Add(leftPanel);
i.Add(rightPanel);
}))))
using System;using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using Ext.Net;
namespace Admin.Util
{
public static class ExtensionMethods
{
public static Field SetV<T>(Field field, ViewContext viewContext, T model, Func<T, object> memberExpression)
{
if (model != null)
{
var value = memberExpression.Invoke(model);
field.Value = value;
}
return field;
}
public static Field SetEditValue(this Field field, ViewContext viewContext, int value)
{
field.Value = value;
return field;
}
public static Field SetEditValue(this Field field, ViewContext viewContext, int? value)
{
field.Value = value;
return field;
}
public static Field SetEditValue(this Field field, ViewContext viewContext, string value)
{
field.Value = value;
return field;
}
public static List<string> GetPropertyList(this Type type)
{
return type.GetProperties().Select(r => r.Name).OrderBy(r => r).ToList();
}
}
}
Last edited by mj.daly; Nov 06, 2012 at 5:17 PM.