{"id":1401,"date":"2022-08-30T15:16:13","date_gmt":"2022-08-30T15:16:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/15\/jquery-is-not-allowing-line-breaks-in-text-areas-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:13","modified_gmt":"2022-08-30T15:16:13","slug":"jquery-is-not-allowing-line-breaks-in-text-areas-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jquery-is-not-allowing-line-breaks-in-text-areas-collection-of-common-programming-errors\/","title":{"rendered":"Jquery is not allowing line breaks in text areas-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m having a weird issue. When adding support for Jquery 1.7.2, I am unable to add line-breaks to textareas in forms. When I click, enter, nothing happens.<\/p>\n<p>I fiddled with the source code in jquery, and found that if I commented out the following code (on line 4845)<\/p>\n<pre><code>for ( var type in Expr.match ) {\n    Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (\/(?![^\\[]*\\])(?![^\\(]*\\))\/.source) );\n    Expr.leftMatch[ type ] = new RegExp( \/(^(?:.|\\r|\\n)*?)\/.source + Expr.match[ type ].source.replace(\/\\\\(\\d+)\/g, fescape) );\n}\n<\/code><\/pre>\n<p>the ability to add line breaks was restored. I&#8217;m not seeing anyone else having this issue, so I&#8217;m guessing something else is going on. However, my question is: what is the purpose of the code above (I&#8217;m not very javascript-savvy), and does removing it pose any risk? I&#8217;d like to just remove the code and restore line break ability to textareas, but don&#8217;t want to bork the site unknowingly. I did notice that after doing this, I&#8217;m seeing an error in the js console:<\/p>\n<pre><code>Uncaught TypeError: Cannot call method 'exec' of undefined -- jquery.js:4185\n<\/code><\/pre>\n<p>Any help would be greatly appreciated!<\/p>\n<p>Here is some code sample. The html:<\/p>\n<pre><code>    \n  \n    <\/code><\/pre>\n<ol>\n<li><code>Activity Type\u00a0<em>*<\/em> CallConnectivity MeetingConversationEmail (incoming)Email (outgoing)Implementation NotesMeeting MinutesTaskTip \/ Unusual Attribute<\/code><\/li>\n<li><code>Summary\u00a0<em>*<\/em><\/code><\/li>\n<li><code>Details\u00a0<\/code><\/li>\n<\/ol>\n<pre>\n  \n  \n  \n<\/pre>\n<p><code>And the javascript that isn't included with other plugins:<\/code><\/p>\n<pre><code><code>\n\/\/ Dynamic lookup of C2 companies\n$(document).ready(function ()\n{\n  $(window).keydown(function(event)\n  {\n    if(event.keyCode == 13) \n    {\n      event.preventDefault();\n      return false;\n    }\n  });\n  $(\"#search_input\").autocomplete(\n  {\n    source: function(request,response)\n    {\n      $(\"#loading-search\").show();\n      $(\"#no-results\").hide();\n      $.getJSON(\"\/services\/json\/cust_search.php\",request,function(data) \n      {\n        response(data);\n        $(\"#loading-search\").hide();\n        if (data.length == 0)\n        {\n          $(\"#no-results\").show();\n        } else\n        {\n          $(\"#no-results\").hide();\n        }\n      });\n    },                                              \n    minLength: 3,\n    select: function(event,ui)\n    {\n      $(\"#search_input\").hide();\n      $(\"#search_input\").val(ui.item.value);\n      $(\"#search_source\").val(ui.item.source);\n      $(\"#search-form\").submit();\n    } \n  });\n});\n \n\n\/\/---------------------------------------------------------------------------\n\/\/  Hide all the submenus on start.  When a non-expanded menu is clicked,\n\/\/  expand that menu while collapsing the menu above it.  If a menu is \n\/\/  clicked when its expanded, collapse.\n\/\/---------------------------------------------------------------------------\n$(function() \n{\n\/\/  $(\"dd:not(:first)\").hide();\n  $(\"dd\").hide();\n  $(\"#menu-nexmark\").slideDown(\"fast\");\n  $(\"dt a\").click(function() \n  {\n    var curr_dd = $(this).parent().next();\n     if (curr_dd.css(\"display\") != \"none\")\n    {\n      $(\"dd:visible\").slideUp(\"medium\");\n      return;\n    }\n    $(\"dd:visible\").slideUp(\"slow\");\n    curr_dd.slideDown(\"slow\");\n    return false;\n  });\n});\n\n<\/code><\/code><\/pre>\n<ol>\n<li>\n<p>The issue was this code:<\/p>\n<pre><code>$(window).keydown(function(event)\n  {\n    if(event.keyCode == 13) \n    {\n      event.preventDefault();\n      return false;\n    }\n  });\n<\/code><\/pre>\n<p>Setting it to refer to only the div it impacted (an autocomplete search menu we wanted to disable the ability to click enter on), restored line break functionality everywhere else:<\/p>\n<pre><code>$(\"#somediv\").keydown(function(event)\n  {\n    if(event.keyCode == 13) \n    {\n      event.preventDefault();\n      return false;\n    }\n  });\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-15 09:09:19. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m having a weird issue. When adding support for Jquery 1.7.2, I am unable to add line-breaks to textareas in forms. When I click, enter, nothing happens. I fiddled with the source code in jquery, and found that if I commented out the following code (on line 4845) for ( var type in Expr.match ) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1401","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1401"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1401\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}