Skip to main content

Bug Tracker

Side navigation

#3369 closed enhancement (invalid)

Opened September 14, 2008 04:40PM UTC

Closed November 14, 2008 01:29PM UTC

Last modified March 09, 2012 03:41PM UTC

[autocomplete] 'mustMatch' option as function

Reported by: proasailor Owned by: joern
Priority: major Milestone: 1.3
Component: plugin Version: 1.2.6
Keywords: Cc:
Blocked by: Blocking:
Description

May I suggest that the 'mustMatch' option can be a function, and if it is, it gets called instead of the existing code.

I modified function 'hideResultsNow()' at line 295 as follows, adding a single line:

    function (result) {
        if (typeof options.mustMatch == 'function') {
            options.mustMatch($input, result);
        }
        else if( !result ) { // as before!
            // if no value found, clear the input box

This allows me to define a 'mustMatch($input, result)' function that adds a CSS class to highlight the field and a mouseover event to show a special dialog for adding the unrecognized term to the approved list.

The 'mustMatch()' function is called for both values of 'result', which allows me to also reliably _remove_ a flag for "invalid terminology", as well as set that flag in the first place.

Attachments (2)
  • code_mustMatch.gif (16.3 KB) - added by proasailor October 15, 2008 08:35AM UTC.

    proposed code changes for 'options.multiple' as a function

  • vocab_dialog.gif (8.4 KB) - added by proasailor September 17, 2008 01:57AM UTC.

    field highlight and dialog box appear when invalid term is typed

Change History (5)

Changed September 14, 2008 08:38PM UTC by joern comment:1

need: ReviewTest Case
owner: → joern
summary: Autocomplete plugin: 'mustMatch' option as function[autocomplete] 'mustMatch' option as function
type: bugenhancement

Changed September 17, 2008 01:51AM UTC by proasailor comment:2

Further experience with what I'm trying to accomplish shows that the single change I suggested isn't quite enough... for one thing, it helps to pass back the value of 'hasFocus', because if the field no longer has focus, then I don't want to highlight it and activate the dialog, which can happen as a result of AJAX delay - in 'hideResultsNow()':

options.mustMatch($input, result, hasFocus);

I also found it necessary to add a similar call to function 'receiveData()' in order to turn off the highlight/dialog when backspacing, though it doesn't seem to work reliably in all cases, esp. in Firefox or when using the <Delete> key:

	function receiveData(q, data) {
		if ( data && data.length && hasFocus ) {
			stopLoading();
			select.display(data, q);
			autoFill(q, data[0].value);
			select.show();
			if (typeof options.mustMatch == 'function') {
				options.mustMatch($input, true, hasFocus);
			}
		} else {
			hideResultsNow();
		}
	};

So... where I am calling the 'mustMatch()' function might not be quite optimal yet, though these two changes have gone a long way toward highlighting the field and presenting a functional "Suggest New Term" dialog when characters are typed that create an invalid term.

Changed September 17, 2008 01:58AM UTC by proasailor comment:3

Example code showing how the autocomplete is created using the 'mustMatch' function:

$(inputElm).autocomplete(MultiRowBDL.apiAcUrl, {delay:50, cacheLength:1, autoFill: true, extraParams: extra, matchContains: true, mustMatch: function(inputObj, result, hasFocus) {
		if (result) { // turn highlight/dialog OFF
			MultiRowBDL.clrError(inputObj.get()[0]);
			MultiRowBDL.errMsgOffOff(inputObj.get()[0]);
		}
		else if (inputObj.val() && hasFocus) { // turn highlight/dialog ON
			inputObj.get()[0].setAttribute('err_msgBLD', '|' + MultiRowBDL.vocabErrMsg);
			MultiRowBDL.setError(inputObj.get()[0]);
			MultiRowBDL.errMsgOnFld(inputObj.get()[0], true);
		}
	}
});

Changed October 15, 2008 08:34AM UTC by proasailor comment:4

NOTE: Extensive experience with this code has led to some changes for the proposed implementation. The changes are highlighted in green on the attachment called code_mustMatch.gif and a working test case has been provided to the plugin's author.

Changed November 14, 2008 01:29PM UTC by joern comment:5

resolution: → invalid
status: newclosed

Moved to UI bugtracker: http://ui.jquery.com/bugs/ticket/3586