forked from saurabh/personal-journal
fixed bug for autocomplete in member personal journals
This commit is contained in:
parent
075acef5d8
commit
5ac4d065e2
|
@ -1,34 +1,33 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
var map = {},
|
||||||
|
members = [],
|
||||||
|
data = <%= raw @members_data %>;
|
||||||
|
$.each(data, function (i, member) {
|
||||||
|
map[member.memberName] = member;
|
||||||
|
members.push(member.memberName);
|
||||||
|
});
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('#search').typeahead({
|
$('#member_autocomplete').typeahead({
|
||||||
source: function (query, process) {
|
source: function (query, process) {
|
||||||
members = [];
|
return members;
|
||||||
map = {};
|
},
|
||||||
|
updater: function (item) {
|
||||||
var data = <%=raw @members_data%>;
|
selectedMember = map[item].memberId;
|
||||||
$.each(data, function (i, member) {
|
$('#member_value').val(selectedMember);
|
||||||
map[member.memberName] = member;
|
return item;
|
||||||
members.push(member.memberName);
|
},
|
||||||
});
|
matcher: function (item) {
|
||||||
process(members);
|
if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
|
||||||
},
|
return true;
|
||||||
updater: function (item) {
|
}
|
||||||
selectedMember = map[item].memberId;
|
},
|
||||||
$('#member_value').val(selectedMember);
|
sorter: function (items) {
|
||||||
return item;
|
return items.sort();
|
||||||
},
|
},
|
||||||
matcher: function (item) {
|
highlighter: function (item) {
|
||||||
if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
|
var regex = new RegExp( '(' + this.query + ')', 'gi' );
|
||||||
return true;
|
return item.replace( regex, "<strong>$1</strong>" );
|
||||||
}
|
},
|
||||||
},
|
|
||||||
sorter: function (items) {
|
|
||||||
return items.sort();
|
|
||||||
},
|
|
||||||
highlighter: function (item) {
|
|
||||||
var regex = new RegExp( '(' + this.query + ')', 'gi' );
|
|
||||||
return item.replace( regex, "<strong>$1</strong>" );
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
|
@ -88,7 +88,7 @@
|
||||||
<div class="control-group input-title">
|
<div class="control-group input-title">
|
||||||
<label class="control-label muted"><%= t("personal_journal.author") %></label>
|
<label class="control-label muted"><%= t("personal_journal.author") %></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.text_field :member_profile_id, id: "search", autocomplete: "off", data: { provide: "typeahead"}, class: "input-block-level", value: (@journal_paper.member_profile.name rescue nil), placeholder: t("personal_journal.author")%>
|
<%= f.text_field :member_profile_id, id: "member_autocomplete", autocomplete: "off", data: { provide: "typeahead"}, class: "input-block-level", value: (@journal_paper.member_profile.name rescue nil), placeholder: t("personal_journal.author")%>
|
||||||
|
|
||||||
<%= f.hidden_field :member_profile_id, value: (@journal_paper.member_profile_id ? @journal_paper.member_profile_id : ""), id: "member_value" %>
|
<%= f.hidden_field :member_profile_id, value: (@journal_paper.member_profile_id ? @journal_paper.member_profile_id : ""), id: "member_value" %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -311,8 +311,6 @@
|
||||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||||
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
|
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<%= render 'author_autocomplete'%>
|
<%= render 'author_autocomplete'%>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
Loading…
Reference in New Issue