On enter key, form is submitted

On enter key, form is submitted



I am using bootstrap input tags like this



myPage.html


<form th:object="$field" name="modal" method="post" th:action="@/ajouterFieldEcran">
...

<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control col-sm-12" value=""
data-role="tagsinput" id="tags">
</div>
</div>


...



I get the example from this post Bootstrap tags input not displaying the tags



The problem is when I am typing the value and press enter to submit it in the input the form that is submitted.





You don't want to submit the form? or do you want to do something else?
– kiranvj
Sep 1 at 8:33





i have a button that submit the form the thing that i want is : when the user insert a value in the input the input tags take it as a value
– Yagami Light
Sep 1 at 8:36





Any valuable example will be nice
– Yagami Light
Sep 1 at 8:38





better write demo using like jsfiddle.net to reproduce your problem.
– Pengcheng
Sep 1 at 8:45




1 Answer
1



You can disable enter key in input tags like this


$(function()
$("input").keydown(function(event)
if (event.keyCode == 13)
event.preventDefault();

);
);



put this inside your script tag



Remove col-sm-12 from input class, you don't need that.


col-sm-12



Also please note that you cannot use enter key in a text box for new line (input type='text' are single line by design), for multiline text you need to use textarea


textarea





the thing is that the value isn't displayed any idea why ?!?
– Yagami Light
Sep 1 at 8:42





You mean if you type any letter its not shown in the input box?
– kiranvj
Sep 1 at 8:44





Thank's it's worked
– Yagami Light
Sep 1 at 8:51



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)