selected = context.data.$container.find( '.suggestions-result-current' );
$.suggestions.hide( context );
if ( selected.length === 0 || context.data.selectedWithMouse ) {
- // if nothing is selected OR if something was selected with the mouse,
- // cancel any current requests and submit the form
+ // If nothing is selected or if something was selected with the mouse
+ // cancel any current requests and allow the form to be submitted
+ // (simply don't prevent default behavior).
$.suggestions.cancel( context );
- context.config.$region.closest( 'form' ).submit();
+ preventDefault = false;
} else if ( selected.is( '.suggestions-special' ) ) {
if ( typeof context.config.special.select === 'function' ) {
- context.config.special.select.call( selected, context.data.$textbox );
+ // Allow the callback to decide whether to prevent default or not
+ if ( context.config.special.select.call( selected, context.data.$textbox ) === true ) {
+ preventDefault = false;
+ }
}
} else {
+ $.suggestions.highlight( context, selected, true );
+
if ( typeof context.config.result.select === 'function' ) {
- $.suggestions.highlight( context, selected, true );
- context.config.result.select.call( selected, context.data.$textbox );
- } else {
- $.suggestions.highlight( context, selected, true );
+ // Allow the callback to decide whether to prevent default or not
+ if ( context.config.result.select.call( selected, context.data.$textbox ) === true ) {
+ preventDefault = false;
+ }
}
}
break;
}
if ( preventDefault ) {
e.preventDefault();
- e.stopImmediatePropagation();
+ e.stopPropagation();
}
}
};
},
result: {
render: renderFunction,
- select: function ( $input ) {
- $input.closest( 'form' ).submit();
+ select: function () {
+ return true; // allow the form to be submitted
}
},
delay: 120,
$searchInput.suggestions( {
result: {
render: renderFunction,
- select: function ( $input ) {
- $input.closest( 'form' ).submit();
+ select: function () {
+ return true; // allow the form to be submitted
}
},
special: {
render: specialRenderFunction,
select: function ( $input ) {
$input.closest( 'form' )
- .append( $( '<input type="hidden" name="fulltext" value="1"/>' ) )
- .submit();
+ .append( $( '<input type="hidden" name="fulltext" value="1"/>' ) );
+ return true; // allow the form to be submitted
}
},
$region: $searchRegion