0

So, long story short, Microsoft's CU turned off the complex lookup functionality that we loved and locked it down so we can't turn it back on. Rolling back the update isn't an option, so I am now tasked with recreating the functionality on the New Item form using jQuery.

The form has two fields that I'm working with - a text box (input) and a drop-down that pulls values from another list (select). To recreate the previous functionality, I need to search the drop-down for the value being typed into the text box. The snippet below (in theory) tries to set the select value to that text.

<script type="text/javascript">
$(document).ready(function(){

var strBidName = $("input[title='Bid Title']");

strBidName.keyUp(function()     {
$("select[title='Project Name'] option[text=' + strBidName + ']").prop('selected','selected');

 });

});
</script>

I've tried several variations of the last line with no success. I've also tried using a focusOut event instead of keyUp. No success. Each option in the SELECT field has a value (the item ID) and a text label (what you see in the drop-down list). I have to use the text label because I won't know the item ID.

Have any other SP admins had to do this? I know there are 3rd-party products that supply the functionality, but it should be possible using jQuery, right?

Windows 7/10 clients, IE 11, SP2013 enterprise, jQuery 1.11 being used


EXAMPLE:

So if a user is typing "1200 Roadway Avenue" into the BID TITLE field, and there's already a project in the drop-down called "1200 Roadway", I want that option to be selected to show the user that it already exists in the list.

  • Bit hard to read with the encoded HTMLentities. You want to change an option value in the DOM and set it to selected? – Danny '365CSI' Engelman Mar 15 '17 at 16:04
  • Sorry about that - removed the encoding and added an example of what I mean – Omegacron Mar 15 '17 at 16:35
  • option[text=' + BidNameFixed + '] is trying to find OPTION tags with a 'text' data-attribute; I would start checking if those exist. Note: this is not a SharePoint problem, basic DOM element operations: stackoverflow.com/questions/29452870/… – Danny '365CSI' Engelman Mar 15 '17 at 17:50
  • @Danny'365CSI'Engelman - the jQuery solution may not be specific to SharePoint, but the issue I'm attempting to fix is. I've seen numerous admins complaining that complex lookups no longer work in SP after applying an update after the April 2016 CU, so the eventual answer should prove useful to have on this site. – Omegacron Mar 15 '17 at 18:07
  • I took out the code that was stripping out characters/words - I know that part works, so it's not relevant to the question. – Omegacron Mar 16 '17 at 15:38
1

Your keyup function should work as follows:

strBidName.keyUp(function () {
    $("select[title='Project Name'] option:contains(" + this.value + "):eq(0)").prop("selected", true);
}

This will select the first option (:eq(0)) in the select where the string from your textbox is contained anywhere in the text of the option. Also note the correct use of .prop()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.