818824b3ba8a513c0c2a1934f060c017ff94a861
larrym
  Thu Aug 2 13:26:20 2012 -0700
handle edge case of user zeroing out the positionInput box
diff --git src/hg/js/autocomplete.js src/hg/js/autocomplete.js
index fe2bda5..8121a45 100644
--- src/hg/js/autocomplete.js
+++ src/hg/js/autocomplete.js
@@ -55,38 +55,38 @@
 
     updateFindMatches: function(val)
     {
         // highlight genes choosen from suggest list (#6330)
         if($('#hgFindMatches').length)
             $('#hgFindMatches').val(val);
         else
             $('#positionInput').parents('form').append("<input type='hidden' id='hgFindMatches' name='hgFind.matches' " + "value='" + val + "'>");
     },
 
     init: function (db, assemblySupportsGeneSuggest, selectCallback, clickCallback)
     {
     // selectCallback(item): called when the user selects a new genomic position from the list
     // clickCallback(position): called when the user clicks on positionDisplay
         var lastSelected = null;    // this is the last value entered by the user via a suggestion (used to distinguish manual entry in the same field)
-        var str;
+        var waterMark;
         if(assemblySupportsGeneSuggest) {
-            str = "enter position, gene symbol or search terms";
+            waterMark = "enter position, gene symbol or search terms";
         } else {
-            str = "enter position or search terms";
+            waterMark = "enter position or search terms";
         }
         $('#positionInput').val("");
-        $('#positionInput').Watermark(str, '#686868');
+        $('#positionInput').Watermark(waterMark, '#686868');
         if(assemblySupportsGeneSuggest) {
             $('#positionInput').autocomplete({
                 delay: 500,
                 minLength: 2,
                 source: this.ajaxGet(db),
                 open: function(event, ui) {
                     var pos = $(this).offset().top + $(this).height();
                     if (!isNaN(pos)) {
                         var maxHeight = $(window).height() - pos - 30;  // take off a little more because IE needs it
                         var auto = $('.ui-autocomplete');
                         var curHeight = $(auto).children().length * 21;
                         if (curHeight > maxHeight)
                             $(auto).css({maxHeight: maxHeight+'px', overflow:'scroll'});
                         else
                             $(auto).css({maxHeight: 'none', overflow:'hidden'});
@@ -98,27 +98,31 @@
                         suggestBox.updateFindMatches(ui.item.internalId);
                         // jQuery('body').css('cursor', 'wait');
                         // document.TrackHeaderForm.submit();
                     }
             });
         }
 
         // I want to set focus to the suggest element, but unforunately that prevents PgUp/PgDn from
         // working, which is a major annoyance.
         // $('#positionInput').focus();
 
         $("#positionInput").change(function(event) {
                                        if(!lastSelected || lastSelected != $('#positionInput').val()) {
                                            // This handles case where user typed or edited something rather than choosing from a suggest list;
                                            // in this case, we only change the position hidden; we do NOT update the displayed coordinates.
-                                           $('#position').val($('#positionInput').val());
+                                           var val = $('#positionInput').val();
+                                           if(!val || val.length == 0 || val == waterMark)
+                                               // handles case where users zeroes out positionInput; in that case we revert to currently displayed position
+                                               val = $('#positionDisplay').text();
+                                           $('#position').val(val);
                                            suggestBox.clearFindMatches();
                                        }
                                    });
         $("#positionDisplay").click(function(event) {
                                         // this let's the user click on the genomic position (e.g. if they want to edit it)
                                         clickCallback($(this).text());
                                         $('#positionInput').val($(this).text());
                                         suggestBox.clearFindMatches();
                                     });
     }
 }