当一个用户向另一个用户发送消息时。他们可以选择要发送到的个人资料类型。(普通或经理)...我正在使用“recipient_type”在后端检查要将其发送到哪个配置文件,如何让我的自动完成功能为我选择隐藏的单选按钮?
自动完成看起来像这样:
To :John Doe - Manager
或
To: John Doe
模板:
<div class="hide">
<input type="radio" id="id_recipient_type" name="recipient_type" value="0" />
<input type="radio" id="id_recipient_type" name="recipient_type" value="1" />
</div>
<div class="inline-block">
<label for="id_omnibox"></label>
<input type="hidden" name="recipient_username" id="id_recipient_username" />
<input id="message-to" class="required input-text" style="width: 145%;"name="omnibox" placeholder="Search for user..." autocomplte="on" type="text" />
</div>
脚本:
$(document).ready(function(){
$.get('/autocomplete/message/', function(data) {
var completions = new Array();
var dict = JSON.parse(data, function(key, value) {
completions.push(key);
return value;
});
$('#message-to').autocomplete({
source: completions,
minLength: 1,
select: function(value, data){
$('#id_recipient_username').val(dict[data.item.value])
split_string = data.item.value.split("- ");
$('#id_recipient_type_'+(split_string[1]=="Manager"?"1":"0")).attr('checked', true);
}
});
});
});