+    }
+
+    function ajax_data(term) {
+      var data = {
+        'filter.all:substr:multi::ilike': term,
+        'filter.obsolete': 0,
+        'filter.unit_obj.convertible_to': $convertible_unit && $convertible_unit.val() ? $convertible_unit.val() : '',
+        no_paginate:  $('#no_paginate').prop('checked') ? 1 : 0,
+        current:  $real.val(),
+      };
+
+      if ($type && $type.val())
+        data['filter.type'] = $type.val().split(',');
+
+      if ($unit && $unit.val())
+        data['filter.unit'] = $unit.val().split(',');
+
+      return data;
+    }
+
+    function set_item (item) {
+      if (item.id) {
+        $real.val(item.id);
+        // autocomplete ui has name, use the value for ajax items, which contains displayable_name
+        $dummy.val(item.name ? item.name : item.value);
+      } else {
+        $real.val('');
+        $dummy.val('');
+      }
+      state = STATES.PICKED;
+      last_real = $real.val();
+      last_dummy = $dummy.val();
+      last_unverified_dummy = $dummy.val();
+      $real.trigger('change');
+
+      if (o.fat_set_item && item.id) {
+        $.ajax({
+          url: 'controller.pl?action=Part/show.json',
+          data: { id: item.id },
+          success: function(rsp) {
+            $real.trigger('set_item:PartPicker', rsp);
+          },
+        });
+      } else {
+        $real.trigger('set_item:PartPicker', item);
+      }
+      annotate_state();
+    }
+
+    function make_defined_state () {
+      if (state == STATES.PICKED) {
+        annotate_state();
+        return true
+      } else if (state == STATES.UNDEFINED && $dummy.val() == '')
+        set_item({})
+      else {
+        last_unverified_dummy = $dummy.val();
+        set_item({ id: last_real, name: last_dummy })
+      }
+      annotate_state();
+    }
+
+    function annotate_state () {
+      if (state == STATES.PICKED)
+        $dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED);
+      else if (state == STATES.UNDEFINED && $dummy.val() == '')
+        $dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED);
+      else {
+        last_unverified_dummy = $dummy.val();
+        $dummy.addClass(STATES.UNDEFINED).removeClass(STATES.PICKED);
+      }
+    }
+
+    function update_results () {
+      $.ajax({
+        url: 'controller.pl?action=Part/part_picker_result',
+        data: $.extend({
+            'real_id': $real.val(),
+        }, ajax_data(function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val })),
+        success: function(data){ $('#part_picker_result').html(data) }
+      });