'value' => $value,
'dir' => $this->mDir,
'spellcheck' => $this->getSpellCheck(),
- ] + $this->getTooltipAndAccessKey();
+ ] + $this->getTooltipAndAccessKey() + $this->getDataAttribs();
if ( $this->mClass !== '' ) {
$attribs['class'] = $this->mClass;
protected function getInputWidget( $params ) {
return new OOUI\TextInputWidget( $params );
}
+
+ /**
+ * Returns an array of data-* attributes to add to the field.
+ *
+ * @return array
+ */
+ protected function getDataAttribs() {
+ return [];
+ }
}
$params['relative'] = $this->mParams['relative'];
return new TitleInputWidget( $params );
}
+
+ public function getInputHtml( $value ) {
+ // add mw-searchInput class to enable search suggestions for non-OOUI, too
+ $this->mClass .= 'mw-searchInput';
+
+ // return the HTMLTextField html
+ return parent::getInputHtml( $value );
+ }
+
+ protected function getDataAttribs() {
+ return [
+ 'data-mw-searchsuggest' => FormatJson::encode( [
+ 'wrapAsLink' => false,
+ ] ),
+ ];
+ }
}
// The function used to render the suggestions.
function renderFunction( text, context ) {
- var formData = getFormData( context );
+ var formData = getFormData( context ),
+ textboxConfig = context.data.$textbox.data( 'mw-searchsuggest' ) || {};
// linkParams object is modified and reused
formData.linkParams[ formData.textParam ] = text;
- // this is the container <div>, jQueryfied
- this.text( text )
- .wrap(
+ // this is the container <div>, jQueryfield
+ this.text( text );
+
+ // wrap only as link, if the config doesn't disallow it
+ if ( textboxConfig.wrapAsLink !== false ) {
+ this.wrap(
$( '<a>' )
.attr( 'href', formData.baseHref + $.param( formData.linkParams ) )
.attr( 'title', text )
.addClass( 'mw-searchSuggest-link' )
);
+ }
}
// The function used when the user makes a selection