Does SPDisplayRelatedInfo Work With Normal Input Fields?

Jun 5, 2013 at 9:15 PM
I'm trying to get SPDisplayRelatedInfo to work with a "Single Line Of Text" field, similar to here:-
http://sympmarc.com/2009/11/27/interesting-new-use-for-spdisplayrelatedinfo/

But it doesn't seem to be working. Is it supposed to? The comments in that link weren't clear.

Thanks.
Jun 10, 2013 at 11:25 AM
Can anyone help with this query please? I could really do with using displayrelatedinfo with a text field.
Coordinator
Jun 12, 2013 at 12:12 AM
This worked at one point, but I just tested in my environment with 2013.01 and it no longer does. It was an interesting side effect, really.

M.
Jun 15, 2013 at 11:39 AM
Thanks. That's a shame. I could really do with that functionality.

I have a huge list, that's too big for a normal lookup column and I wanted to use displayrleatedinfo to show details and then set some values in the post function.

Any suggestions about the best way to recreate this functionality?
Coordinator
Jun 17, 2013 at 6:32 PM
I'd suggest using jQueryUI's autocomplete function. You can hook into the select event to look up the additional information and display it.

M.
Jun 18, 2013 at 11:16 AM
Sounds like a good alternative. Thanks.
Jul 17, 2013 at 7:50 PM
Edited Jul 17, 2013 at 7:51 PM
Couple of follow-on questions about JQueryUI Autocomplete.
  1. It's not a show stopper, but it uses the input ID, which (as you'll no doubt be aware) is a huge gibberish name for list fields. Is there anyway around that, or do I just have to use that?
  2. As it's a huge list, is there any way to avoid passing all 10,000+ list items to it? Does SPServices's Autocomplete do that, or does it limit the results? I'm a bit concerned about performance, as it seems a lot of data to fetch.
Thanks.
Coordinator
Jul 17, 2013 at 8:22 PM
If you use smart selectors, you [almost] never need to use the gibberish ids. Usually the column name is contained somewhere in the elements. In the case of a Single line of test, the title attribute is the column name.

In both cases, you set a number of characters typed before a fetch. That will limit the items retrieved if you set up the filtering correctly.

M.
Jul 17, 2013 at 8:35 PM
Thanks.

I'll check out smart selectors.

Sorry, but I'm not sure I follow. Don't I have to retrieve and pass every value to autocomplete 1st? So even if it's set to 2 or 3 characters, I've still had to retrieve everything, but it just won't start filtering immediately. I don't understand how I can filter to limit the items retrieved before I know what's typed.

I'm obviously missing something, but I'm doing as suggested here:-
http://www.itidea.nl/index.php/jquery-spservices-and-autocomplete/
Coordinator
Jul 17, 2013 at 8:54 PM
If you're using the SPServices autocomplete function, then it'll take care of the filtering for you.

If you're wiring up jQueryUI's autocomplete, then you'll want to add your own filtering. Since the user will have already typed at least one character, you can filter for items which start with that character. Given an even distribution, that's 1/26th of your content - 1/36 with numeric values.

M.
Jul 17, 2013 at 9:27 PM
Edited Jul 17, 2013 at 9:32 PM
I can't use the SPServices version as that no longer works on a text field and the list is to big to use a standard look up column, so I'm using JQueryUI.

That makes more sense. How do I call autocomplete after a character or 2 has been typed though? Currently, I'm just calling autocomplete with all values when the form loads.

Sounds like I need to hook into the field onchange event and call it then instead?
Coordinator
Jul 17, 2013 at 9:38 PM
Jul 17, 2013 at 9:59 PM
I'm aware of the minLength option and I'm obviously being really slow here, but I still don't understand how/when I'm supposed to call autocomplete.

I get that I need to call autocomplete after a few characters have been entered and filter my GetListItems call to rows that start with the characters entered. So that means I need to do the data retrieval and call to autocomplete after those characters have been entered right?

So, hook into the onchange event and when x number of characters has been entered, do the spservices call to get the data and feed that into autocomplete?

Does that make sense, or am I just not getting it?

Thanks for your patience.
Jul 18, 2013 at 1:57 AM
@ixwood

Take a look at the autocomplete documentation - specifically the 'source' option: http://api.jqueryui.com/autocomplete/

Take a look at autocomplete examples - specifically the one that uses remote data and JSONP source; 1) http://jqueryui.com/autocomplete/#remote | 2) http://jqueryui.com/autocomplete/#remote-jsonp (Although you will not get JSON data from SP with SPServices, if you get a good understanding of how it works in the demo, you will be able to implement this no problem)

The design is as follows:
  1. use autocomplete on the input field
  2. Set the source option to a function that retrieves values based on the few characters that the user entered.
    a. Alter the response from GetListItems the create the data structure (Array of Objects) that autcomplete expects.
No. 2 above is where the magic happens... You use SPServices to issue a GetListItems (probably setting the max item to 50 (you don't want thousands of records coming back)... The trick is to use the "<Contain>" CAML clause with the value the user entered... That will match anything in that column containing the charterers... As the user enters more characters, the more accurate the results will become.

Hope this helps..

Paul.

( Shameful plug: This widget I created may help: SPLookupField : http://purtuga.github.io/SPWidgets/ - it was created to address this exact need: filter through large lists... If you want to see specifically how I coded it using the design described above, look in the source HERE )

.
Jul 18, 2013 at 8:38 AM
Thanks ptavares. That's very helpful. I'll try it later, but think I finally get it now.

I didn't appreciate that you could make the source a function. Clever!

Your widget looks very interesting.

Thanks again! :-)
Oct 27, 2013 at 2:59 PM
Edited Oct 27, 2013 at 3:00 PM
It's been a while, but finally got back to this. Got the dynamic autocomplete working nicely thanks to your explanation and links Paul.

One other question, which is more autocomplete than SPS, but hoping you'll be around and know... I'm dong some extra logic upon selection, but can't seem to figure out how to ensure my logic is called regardless of how the user selects/doesn't select a value.

If you use the cursor keys to choose a suggestion, "change" and "select" events are fired, but if you just type a value, only "change" is fired and if you use the mouse to choose a selection, only "select".

I need a way to either make "select" fire on keyboard selection, or "change" to fire on mouse selection, so my code runs regardless Any ideas please?
Oct 27, 2013 at 7:00 PM
How about binding your logic to the input field's (not autocomplete) Change event?

That should be triggered anytime the value of the input is set - either by the user manually typing in their value, or my them picking a value from the autocomplete suggestions. If you want the logic to also trigger if the user does not set a value at all (ex: user tabs out of the field) you can also bind the logic to the Blur event as well.


--

_________
Paul T

Oct 27, 2013 at 8:15 PM
Edited Oct 27, 2013 at 8:17 PM
Thanks. Autocomplete docs state this though:-

"This widget manipulates its element's value programmatically, therefore a native change event may not be fired when the element's value changes."

Doesn't sound very promising. Any thoughts, or other ideas?
Oct 28, 2013 at 1:09 AM
Thats true, but you can force it by using Autocomplete events to trigger the native event othe input.

Example, use the autocomplete.change and select hooks to trigger a change on the input, which would then trigger your independently bound events (your business logic) of the input.


--

_________
Paul T