Sha256: dc7a4451740f1e063b5a763aac58da293b1b5a4bba9a80629d59a12123a818cd

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

$.fn.usecodeAutocomplete = function () {
  'use strict';

  this.select2({
    minimumInputLength: 1,
    multiple: false,
    initSelection: function (element, callback) {
      Spree.ajax({
        url: Spree.routes.use_code_search,
        data: {
          ids: element.val()
        },
        success: function(data) {
          callback(data[0]);
        }
      })
    },
    ajax: {
      url: Spree.routes.use_code_search,
      datatype: 'json',
      data:  function (term) {
        return {
          q: term
        };
      },
      results: function (data) {
        return {
          results: data
        };
      }
    },
    formatResult: function (use_codes) {
      if( !use_codes.use_code ){
        return "Enter Avalara Entity Use Code"
      } else {
        return use_codes.use_code + ') Description: ' + use_codes.use_code_description;
      }
    },
    formatSelection: function (use_codes) {
      if( !use_codes.use_code ){
        return "Enter Avalara Entity Use Code"
      } else {
        return use_codes.use_code + ') Description: ' + use_codes.use_code_description;
      }
    }
  });
};

$(document).ready(function () {
  $('.use_code_picker').usecodeAutocomplete();
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_avatax_certified-3.0.0 app/assets/javascripts/spree/backend/use_code_picker.js
solidus_avatax_certified-2.0.0 app/assets/javascripts/spree/backend/use_code_picker.js
solidus_avatax_certified-1.1.0 app/assets/javascripts/spree/backend/use_code_picker.js
solidus_avatax_certified-1.0.0 app/assets/javascripts/spree/backend/use_code_picker.js