简体   繁体   English

jQuery自动完成值未传递到Django表单

[英]Jquery autocomplete value is not being passed to django form

I am trying to get a textInput from Form where in I am pulling values from Jquery Autocomplete. 我试图从Form中获取textInput,其中我从Jquery Autocomplete中提取值。 But the selected value is not being passed to form. 但是所选值未传递到表单。 What am I missing. 我想念什么。

 $(function() { var availableTags = ['Software Engineer', 'Project manager']; $("#id_j_title").autocomplete({ source: availableTags }) }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <form id="search-form" method="POST" action="."> <p> <label for="id_j_title">Enter a keyword for the job title for the new application:</label> <input id="id_j_title" maxlength="11" name="j_title" type="text" /> </p> And Please enter a keyword to search for <input type="submit" value="Select" /> <button>Back</button> </form> 

If you have specified maxlength attribute in django form then this might be the reason as your maxlength value(11) in django is less than populated form data(one of the two strings shown in example) after autocomplete. 如果您以Django形式指定了maxlength属性,则这可能是原因,因为自动完成后django中的maxlength值(11)小于填充的表单数据(示例中显示的两个字符串之一)。 Django form validates data after it receives data from browser. Django表单在从浏览器接收数据后会验证数据。 Try to increase maxlength value in django form. 尝试以Django形式增加maxlength值。 If you have length constrain then please follow below url to filter out autocomplete options based on length. 如果您有长度限制,请按照以下网址根据长度过滤掉自动填充选项。

https://forum.jquery.com/topic/autocomplete-30-4-2010 https://forum.jquery.com/topic/autocomplete-30-4-2010

max_length is causing problem here, as identified by Amit Dhar. 正如阿米特·达尔(Amit Dhar)所指出的那样,max_length引起了问题。 Either remove it, or increase its value to a number that will easily accommodate the values of titles. 删除它,或将其值增加到可以轻松容纳标题值的数字。

 <form id="search-form" method="POST" action=".">
  <p>
<label for="id_j_title">Enter a keyword for the job title for the new application:</label>
<input id="id_j_title" maxlength="20" name="j_title" type="text" />
</p>
And Please enter a keyword to search for
<input type="submit" value="Select" />
<button>Back</button>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM