Skip to content

Commit 960011c

Browse files
committed
Conflict resolution
1 parent 681d1f4 commit 960011c

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

lib/assets/javascripts/autocomplete-rails-uncompressed.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
jQuery(e).autocomplete({
5858
appendTo: e.append_to,
5959
autoFocus: e.autoFocus,
60+
delay: jQuery(e).attr('delay') || 0,
6061
source: function( request, response ) {
6162
var firedFrom = this.element[0];
6263
var params = {term: extractLast( request.term )};
@@ -135,21 +136,26 @@
135136
jQuery(jQuery(this).attr('data-id-element')).val(ui.item.id);
136137
}
137138
if (jQuery(this).attr('data-update-elements')) {
138-
var data = jQuery(this).data(ui.item.id.toString());
139+
var data = ui.item;
140+
var new_record = ui.item.value.indexOf('Create New') != -1 ? true : false;
139141
var update_elements = jQuery.parseJSON(jQuery(this).attr("data-update-elements"));
140142
for (var key in update_elements) {
141-
var element = jQuery(update_elements[key]);
142-
if (element.is(':checkbox')) {
143-
if (data[key] != null) {
144-
element.prop('checked', data[key]);
145-
}
146-
} else {
147-
element.val(data[key]);
143+
if(jQuery(update_elements[key]).attr("type") === "checkbox"){
144+
if(data[key] === true || data[key] === 1) {
145+
jQuery(update_elements[key]).attr("checked","checked");
146+
}
147+
else {
148+
jQuery(update_elements[key]).removeAttr("checked");
149+
}
150+
}
151+
else{
152+
if((new_record && data[key] && data[key].indexOf('Create New') == -1) || !new_record){
153+
jQuery(update_elements[key]).val(data[key]);
154+
}else{
155+
jQuery(update_elements[key]).val('');
148156
}
149-
}
150-
if(jQuery(update_elements[key]).attr("type") === "checkbox"){
151-
jQuery(update_elements[key]).attr("checked","checked");
152-
}
157+
}
158+
}
153159
}
154160
}
155161
var remember_string = this.value;
@@ -160,6 +166,7 @@
160166
}
161167
});
162168
jQuery(e).trigger('railsAutocomplete.select', ui);
169+
163170
return false;
164171
}
165172
});

0 commit comments

Comments
 (0)