Pressing enter in a textarea submits the form

  1. #1

    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
    @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 = "&nbsp;"},
                                                                   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.
  2. #2
    <form id="Form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:TextField FieldLabel="Press Enter" AnchorHorizontal="100%" runat="server">
        <Listeners>
            <SpecialKey Fn="StopIfEnter" />
        </Listeners>
    </ext:TextField>
    </form>
    <script type="text/javascript">
        var StopIfEnter = function (field, e) {
            if (e.getKey() == e.ENTER) {
                e.stopEvent();
            }
        };
    </script>
  3. #3
    Correct me if I'm wrong, but that code should not be needed.

    If that code is needed then either Ext.Net or ExtJS is breaking the normal/ expected behaviour of HTML controls?
  4. #4
    Quote Originally Posted by mj.daly View Post
    If that code is needed then either Ext.Net or ExtJS is breaking the normal/ expected behaviour of HTML controls?
    There is the same behavior with a pure <textarea> HTML element.

Similar Threads

  1. Replies: 0
    Last Post: Aug 10, 2012, 7:31 AM
  2. Replies: 4
    Last Post: Oct 10, 2011, 4:28 PM
  3. Replies: 4
    Last Post: Apr 14, 2010, 4:12 PM
  4. Replies: 1
    Last Post: Jul 20, 2009, 6:44 AM
  5. [CLOSED] Htmleditor problem on Pressing Enter key
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 15, 2009, 12:25 PM

Posting Permissions