<commit_before>:ruby
  config = field.associated_model_config
  related_id = params[:associations] && params[:associations][field.name.to_s]
  
  
  xhr = field.associated_collection_count > 100
  
  if @object.new_record? && related_id.present? && related_id != 'new'
    selected = field.associated_model_config.abstract_model.get(related_id)
    selected_id = selected.id
    selected_name = selected.send(config.object_label_method)
  else
    selected_id = field.selected_id
    selected_name = field.formatted_value
  end
  
  if xhr
    collection = [[selected_name, selected_id]]
  else
    collection = field.associated_collection(@authorization_adapter)
  end

= field_wrapper_for(form, field) do
  = form.select field.method_name, collection, { :selected => selected_id, :include_blank => true }, field.html_attributes
  - if authorized? :new, config.abstract_model
    - path_hash = { :model_name => config.abstract_model.to_param }
    - path_hash.merge!({ :associations => { field.inverse_of => (@object.id || 'new') } }) if field.inverse_of
    = link_to t('admin.actions.create').capitalize + ' ' + config.abstract_model.pretty_name.downcase, new_path(path_hash), :class => "createAssociatedRecord"
- head_javascript do
  $j(document).ready(function($){
  $("##{"#{field.dom_id}"}").filteringSelect({
  - if xhr
    createQuery: function(query) {
    return { query: query }
    },
    source: "#{list_path(config.abstract_model.to_param, :compact => true)}"
  });
  if($("div.createAssociatedRecordDialog").length == 0) {
  $(".#{"#{field.dom_id}"} .createAssociatedRecord").remoteForm({ dialogClass: "createAssociatedRecordDialog" });
  } else { // hide link if we already are inside a dialog (endless issues on nested dialogs with JS)
  $(".#{"#{field.dom_id}"} .createAssociatedRecord").hide();
  }
  });
<commit_msg>Fixed broken filtering select widget by html_safing value for source.<commit_after>:ruby
  config = field.associated_model_config
  related_id = params[:associations] && params[:associations][field.name.to_s]
  
  
  xhr = field.associated_collection_count > 100
  
  if @object.new_record? && related_id.present? && related_id != 'new'
    selected = field.associated_model_config.abstract_model.get(related_id)
    selected_id = selected.id
    selected_name = selected.send(config.object_label_method)
  else
    selected_id = field.selected_id
    selected_name = field.formatted_value
  end
  
  if xhr
    collection = [[selected_name, selected_id]]
  else
    collection = field.associated_collection(@authorization_adapter)
  end

= field_wrapper_for(form, field) do
  = form.select field.method_name, collection, { :selected => selected_id, :include_blank => true }, field.html_attributes
  - if authorized? :new, config.abstract_model
    - path_hash = { :model_name => config.abstract_model.to_param }
    - path_hash.merge!({ :associations => { field.inverse_of => (@object.id || 'new') } }) if field.inverse_of
    = link_to t('admin.actions.create').capitalize + ' ' + config.abstract_model.pretty_name.downcase, new_path(path_hash), :class => "createAssociatedRecord"
- head_javascript do
  $j(document).ready(function($){
  $("##{"#{field.dom_id}"}").filteringSelect({
  - if xhr
    createQuery: function(query) {
    return { query: query }
    },
    source: "#{list_path(config.abstract_model.to_param, :compact => true).html_safe}"
  });
  if($("div.createAssociatedRecordDialog").length == 0) {
  $(".#{"#{field.dom_id}"} .createAssociatedRecord").remoteForm({ dialogClass: "createAssociatedRecordDialog" });
  } else { // hide link if we already are inside a dialog (endless issues on nested dialogs with JS)
  $(".#{"#{field.dom_id}"} .createAssociatedRecord").hide();
  }
  });

{'fraction_non_alphanumeric': 0.14331550802139037, 'fraction_numerical': 0.0021390374331550803, 'mean_word_length': 4.634036144578313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6099997', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1186, 'n_words': 221}