Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 57 additions & 5 deletions paper-typeahead-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ <h3>{{label}}</h3>
value:false,
notify:true
},
/**
* A boolean property to tell if need to open show up with empty input string.
* isAllowSuggestOnEmptyInput
*/
isAllowSuggestOnEmptyInput: {
type:Boolean,
value:false
},
/**
* A boolean property to tell if need to open show up on focusing input element.
*/
suggestOnFocus: {
type:Boolean,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both twitter typeahead.js and google.com search has this suggest on focus and clear suggest when lose focus, so I think maybe it's good to have the default value to be true to encourage developer to be consistent with common user experience.

value:false
},
/**
* Input value.
*/
Expand All @@ -246,6 +261,13 @@ <h3>{{label}}</h3>
type:Object,
notify:true
},
/**
* Bind this to the <paper-input>'s autocomplete property.
*/
autocomplete:{
type:String,
value:'address-level4'
},
/**
* Bind this to the <paper-input>'s alwaysFloatLabel property.
*/
Expand Down Expand Up @@ -296,6 +318,11 @@ <h3>{{label}}</h3>
pattern:String
},

listeners: {
'focus': '_onInputFocus',
'blur': '_onInputBlur'
},

// Element Lifecycle

ready: function() {
Expand All @@ -313,7 +340,7 @@ <h3>{{label}}</h3>
}
});
var input = Polymer.dom(this.root).querySelector('paper-input');
input.$.input.autocomplete = 'address-level4';
input.$.input.autocomplete = this.autocomplete;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any use case you think it's necessary to assign this autocomplete value of the input?

This line of code is to fix the Chrome Autofilling problem.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without autocomplete="Off" I have suggest(browser) on
suggest(paper-typeahead-input). And browser suggest blocks
paper-typeahead-input suggesting. Maybe you know another way to resolve
this issue?
[image: Inline images 1]

On 13 July 2016 at 23:31, Tianxiang Zhang notifications@github.com wrote:

In paper-typeahead-input.html
#30 (comment)
:

@@ -313,7 +340,7 @@
}
});
var input = Polymer.dom(this.root).querySelector('paper-input');

  •  input.$.input.autocomplete = 'address-level4';
    
  •  input.$.input.autocomplete = this.autocomplete;
    

Do you have any use case you think it's necessary to assign this
autocomplete value of the input?

This line of code is to fix the Chrome Autofilling problem.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/cheonhyangzhang/paper-typeahead-input/pull/30/files/dfdc34b0472906d1f9c7005d4442b0162ab8c4f8#r70702583,
or mute the thread
https://github.com/notifications/unsubscribe/AG0SnOjkUkLbKRf2A1xmursYW3wXOD8nks5qVUsYgaJpZM4JKWUL
.

C уважением, Пличко Павел

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent autofilling of Chrome, autocomplete="Off" is not a reliable solution. Chrome Browser Ignoring AutoComplete=Off. See discussion here http://stackoverflow.com/questions/12374442/chrome-browser-ignoring-autocomplete-off. And plus, the expected behavior of paper-typeahead-input is to provide its own suggest, so I don't see why we need to expose this autocomplete property of inner input as the property of paper-typeahead-input.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ок, no problem.But this solution is working for me.

On 18 July 2016 at 17:13, Tianxiang Zhang notifications@github.com wrote:

In paper-typeahead-input.html
#30 (comment)
:

@@ -313,7 +340,7 @@
}
});
var input = Polymer.dom(this.root).querySelector('paper-input');

  •  input.$.input.autocomplete = 'address-level4';
    
  •  input.$.input.autocomplete = this.autocomplete;
    

To prevent autofilling of Chrome, autocomplete="Off" is not a reliable
solution. Chrome Browser Ignoring AutoComplete=Off. See discussion here
http://stackoverflow.com/questions/12374442/chrome-browser-ignoring-autocomplete-off.
And plus, the expected behavior of paper-typeahead-input is to provide its
own suggest, so I don't see why we need to expose this autocomplete
property of inner input as the property of paper-typeahead-input.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/cheonhyangzhang/paper-typeahead-input/pull/30/files/dfdc34b0472906d1f9c7005d4442b0162ab8c4f8#r71153857,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AG0SnBPJdniRjFkkSU_AG-yL2I-8STNQks5qW4n-gaJpZM4JKWUL
.

C уважением, Пличко Павел

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do u mean you are using autocomplete="off"? because based on your current code, it's setting autocomplete="address-level4" still.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is my usage, that prevents chrome suggesting.

<paper-typeahead-input
input-value="{{_selectorValue}}"
id="query_input"
local-candidates="[[transactions]]"
placeholder="Transaction ID"
autocomplete="Off"
is-allow-suggest-on-empty-input="true"
suggest-on-focus="true"
max-suggestions="10"

On 18 July 2016 at 17:16, Tianxiang Zhang notifications@github.com wrote:

In paper-typeahead-input.html
#30 (comment)
:

@@ -313,7 +340,7 @@
}
});
var input = Polymer.dom(this.root).querySelector('paper-input');

  •  input.$.input.autocomplete = 'address-level4';
    
  •  input.$.input.autocomplete = this.autocomplete;
    

do u mean you are using autocomplete="off"? because based on your current
code, it's setting autocomplete="address-level4" still.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/cheonhyangzhang/paper-typeahead-input/pull/30/files/dfdc34b0472906d1f9c7005d4442b0162ab8c4f8#r71154420,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AG0SnMfV0Oamco4x7R5UNbHdlgCM5fYQks5qW4qzgaJpZM4JKWUL
.

C уважением, Пличко Павел

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. But if I didn't remember wrong, I have been searching for the chrome suggesting problem a lot before and the conclusion of discussions I found is that autocomplete="Off" is not reliable, workaround is to use autocomplete="address-level4". But it was quite ago, I am not sure if Chrome made some updates to change the situation here. If you like, can you search for some docs or evidence to say autocomplete="Off" is working now? Also, you change it to be "Off" is it because the original implementation using autocomplete="address-level4" is not working?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 18 July 2016 at 17:32, Tianxiang Zhang notifications@github.com wrote:

In paper-typeahead-input.html
#30 (comment)
:

@@ -313,7 +340,7 @@
}
});
var input = Polymer.dom(this.root).querySelector('paper-input');

  •  input.$.input.autocomplete = 'address-level4';
    
  •  input.$.input.autocomplete = this.autocomplete;
    

Got it. But if I didn't remember wrong, I have been searching for the
chrome suggesting problem a lot before and the conclusion of discussions I
found is that autocomplete="Off" is not reliable, workaround is to use
autocomplete="address-level4". But it was quite ago, I am not sure if
Chrome made some updates to change the situation here. If you like, can you
search for some docs or evidence to say autocomplete="Off" is working now?
Also, you change it to be "Off" is it because the original implementation
using autocomplete="address-level4" is not working?

I just read a lot about this issue and I understand what you meaning. I
will try to find out why Its working for me and let you know about the
result.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/cheonhyangzhang/paper-typeahead-input/pull/30/files/dfdc34b0472906d1f9c7005d4442b0162ab8c4f8#r71157635,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AG0SnMv-cJiCcUWVzZlFlEDwWauwEf8Fks5qW46DgaJpZM4JKWUL
.

C уважением, Пличко Павел

},

attached: function() {
Expand Down Expand Up @@ -394,7 +421,11 @@ <h3>{{label}}</h3>
* @param {e} event
*/
_keyup: function(e) {
if (e.which == 40){
if (e.which == 27 && this.suggestOnFocus) {
// esc button
this._clearSuggestings();
}
else if (e.which == 40){
//down button
var suggestionsMenu = Polymer.dom(this.root).querySelector('paper-menu');
var selectedItem = suggestionsMenu.focusedItem;
Expand Down Expand Up @@ -473,8 +504,8 @@ <h3>{{label}}</h3>
}
},
_search:function(term){
if (term == ""){
this._suggestions = [];
if (term == "" && !this.isAllowSuggestOnEmptyInput){
Copy link
Owner

@cheonhyangzhang cheonhyangzhang Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a use case that we need to search on empty string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case for suggest items when no chars in the input. When you dont know
the first letter of your item - you can look on existing.
Our case is order number. You must choose from top 10 IDs.

On 18 July 2016 at 18:06, Tianxiang Zhang notifications@github.com wrote:

In paper-typeahead-input.html
#30 (comment)
:

@@ -473,8 +504,8 @@
}
},
_search:function(term){

  •  if (term == ""){
    
  •    this._suggestions = [];
    
  •  if (term == "" && !this.isAllowSuggestOnEmptyInput){
    

Can you give a use case to search on empty string?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/cheonhyangzhang/paper-typeahead-input/pull/30/files/dfdc34b0472906d1f9c7005d4442b0162ab8c4f8#r71164813,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AG0SnJefU7h_e_NhbmavzVUB1mAnyz2Gks5qW5Z4gaJpZM4JKWUL
.

C уважением, Пличко Павел

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. This makes sense. And it's good to have it default to be false.
Can you rename it to be suggestOnEmptyInput instead of isAllowSuggestOnEmptyInput. So that to be consistent with the other property suggestOnFocus.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also note that based on current implementation, the search will go localCandidates, _prefetchedCandidates and remoteCandidates in order. So for you use case, the top 10 will be the first 10 items in localCandidates.

this._clearSuggestings();
return;
}
var patt = new RegExp(term.toLowerCase());
Expand Down Expand Up @@ -543,8 +574,29 @@ <h3>{{label}}</h3>
else{
this._suggestions = matched;
}
},
_clearSuggestings:function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to rename it to be _clearSuggestions to be consistent with other variables used in the code. And also as the name indicated, it should only clear the suggestions, but not make the input lose focus. So maybe create another _ function to only perform lose focus and call it in e.which = 27. P.S. I tried with twitter typeahead.js when clicks on ESC the input don't lose focus. But when I try with google.com or Google drive, the input loses focus when clicks on ESC. I don't know yet what's the better behavior here.

this._suggestions = [];
var input = Polymer.dom(this.root).querySelector('paper-input');
input.$.input.blur();
},
_onInputFocus:function(e, detail) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why when I test locally, the this function _onInputFocus is not triggered when input is focused. And also _onInputBlur is not triggered when lose focus. Do I miss anything to get it working? I already set the suggestOnFocus to be true. ( but this shouldn't matter though.

if ( detail.sourceEvent
&& detail.sourceEvent.relatedTarget == null
&& this.suggestOnFocus
) {
this._search(this.inputValue.trim());
}
},
_onInputBlur:function(e, detail) {
if ( detail.sourceEvent
&& detail.sourceEvent.relatedTarget == null
&& this.suggestOnFocus
) {
this._search(this.inputValue.trim());
this._clearSuggestings();
}
}

});

</script>