This project has moved. For the latest updates, please go here.
1
Vote

SPAutocompleteLookupField.SetValue issue when lookuptext is number or begins with a digit

description

we often use ID in lookup fields such as display field.
And ID is a number.

in the setValue function, a regex is used to reorder choices array.
      // split the string on every pipe character followed by a digit
      choices = choices.split(/\|(?=\d+)/);
         pipeIndex = choices[i].indexOf('|'); // split on the first pipe only
         c.push(choices[i].substring(0, pipeIndex));
         c.push(choices[i].substring(pipeIndex + 1));
But in the case ID is the display field, the above regex split on every '|'.
So the c array is not filled correctly, the value is empty and a System.FormatException occurs

I simply use this line to fill the c array.
   SPAutocompleteLookupField.prototype.SetValue = function (value) {
      var choices, lookupID, lookupText, i, c = [], pipeIndex;

      // a list item ID was passed to the function so attempt to lookup the text value
      choices = this.Textbox.attr('choices');
        tryConsole('choices:'+ choices);
      // options are stored in a choices attribute in the following format:
      // (None)|0|Alpha|1|Bravo|2|Charlie|3
      // split the string on every pipe character
 
      if (isString(value)) {
         // since the pipe character is used as a delimiter above, any values
         // which have a pipe in them were doubled up
         value = value.replace("|", "||");
      }

      // options are stored in a choices attribute in the following format:
      // text|value|text 2|value2
      c=choices.split("|");      
      for (i = 0; i < c.length; i += 2) {
And it seems good.
Do you see any problem with this simple modification ?

Thanks

comments