@@ -103,6 +103,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
103
103
* doSearchWhenEmpty: If it is set to true, it lists all items initially and filters them with the given search phrase. (default:false)
104
104
* verboseHandler: function to be called to return the text to display as verbose output
105
105
* attributes: Array of names for attributes types to display in the list of results
106
+ * showSearchButton: Boolean, indicating whether to use search button for immediate search
106
107
*
107
108
* The styling on this table works like this:
108
109
* <pre>
@@ -192,6 +193,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
192
193
minCharErrorObj . html ( omsgs . minCharRequired . replace ( "_REQUIRED_NUMBER_" , o . minLength ) ) ;
193
194
notification = div . find ( "#searchWidgetNotification" ) ;
194
195
loadingMsgObj = div . find ( "#loadingMsg" ) ;
196
+ showSearchButton = o . showSearchButton ? true : false ;
195
197
196
198
this . _div = div ;
197
199
@@ -201,6 +203,21 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
201
203
if ( o . displayLength < 3 )
202
204
o . displayLength = 3 ;
203
205
206
+ // If need search button
207
+ if ( showSearchButton ) {
208
+ input . after ( "<input type='button' id='searchButton' name='searchButton' value='" + omsgs . searchLabel + "' />" ) ;
209
+ $j ( '#searchButton' ) . click ( function ( ) {
210
+ if ( $j . trim ( input . val ( ) ) != '' || self . options . doSearchWhenEmpty ) {
211
+ //if there is any delay in progress, cancel it
212
+ if ( self . _searchDelayTimer != null ) {
213
+ window . clearTimeout ( self . _searchDelayTimer ) ;
214
+ }
215
+ self . _doSearch ( $j . trim ( input . val ( ) ) ) ;
216
+ input . focus ( ) ;
217
+ }
218
+ } ) ;
219
+ }
220
+
204
221
if ( o . showIncludeVoided ) {
205
222
var tmp = div . find ( "#includeVoided" ) ;
206
223
tmp . after ( "<label for='includeVoided'>" + o . includeVoidedLabel + "</label>" ) ;
@@ -250,11 +267,17 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
250
267
//LEFT(37), UP(38), RIGHT(39), DOWN(40), ENTER(13), HOME(36), END(35), PAGE UP(33), PAGE DOWN(34)
251
268
var kc = event . keyCode ;
252
269
if ( ( ( kc >= 33 ) && ( kc <= 40 ) ) || ( kc == 13 ) ) {
253
- if ( ! ( self . _div . find ( ".openmrsSearchDiv" ) . css ( "display" ) != 'none' ) ) {
270
+ if ( ! ( self . _div . find ( ".openmrsSearchDiv" ) . css ( "display" ) != 'none' ) && ( $j . trim ( input . val ( ) ) == '' ) ) {
254
271
return true ;
255
272
}
256
- if ( kc == 13 )
273
+ if ( kc == 13 ) {
274
+ //if there is any delay in progress, cancel it
275
+ if ( self . _searchDelayTimer != null ) {
276
+ window . clearTimeout ( self . _searchDelayTimer ) ;
277
+ }
257
278
self . _doKeyEnter ( ) ;
279
+ }
280
+
258
281
//kill the event
259
282
event . stopPropagation ( ) ;
260
283
@@ -885,15 +908,22 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
885
908
} ,
886
909
887
910
_doKeyEnter : function ( ) {
911
+
888
912
var selectedRowIndex = null ;
889
913
if ( this . hoverRowSelection != null ) {
890
914
selectedRowIndex = this . hoverRowSelection ;
891
915
} else if ( this . curRowSelection != null ) {
892
916
selectedRowIndex = this . curRowSelection ;
893
917
}
894
918
895
- if ( selectedRowIndex != null )
919
+ if ( selectedRowIndex != null ) {
896
920
this . _doSelected ( selectedRowIndex , this . _results [ selectedRowIndex ] ) ;
921
+ } else if ( showSearchButton ) {
922
+ if ( ( $j . trim ( $j ( '#inputNode' ) . val ( ) ) != '' ) || self . options . doSearchWhenEmpty ) {
923
+ this . _doSearch ( $j . trim ( $j ( '#inputNode' ) . val ( ) ) ) ;
924
+ }
925
+ }
926
+
897
927
} ,
898
928
899
929
_doSelected : function ( position , rowData ) {
0 commit comments