Showing posts with label autocomplete. Show all posts
Showing posts with label autocomplete. Show all posts

Monday, July 9, 2018

p:autocomplete stops working after updating parent via ajax

Leave a Comment

I have a list of autocompletes that is rendered using a p:dataList. Something like shown below:

<h:panelGroup layout="block" id="outerPanel">     <p:dataList rendered="#{bean.myModel.listOfItems.size()>0}"                 var="additionalMP"                 value="#{bean.myModel.listOfItems}"                  rowIndexVar="index" emptyMessage="">          <div class="wrapper ui-g">             <div>               <p:autoComplete                           cache="true"                           value="#{bean.myModel.listOfItems[index]}"                             completeMethod ="#{handler.getAutoCompleteData}"                           rendered ="true"                           required="false"                           scrollHeight="200"                           styleClass="custom"                           forceSelection="true">                     <p:ajax event="query" global="false"/>                        <f:attribute name="filter" value="filterName" />                     <f:attribute name="mode" value="edit" />                                         </p:autoComplete>                                          </div>             <div>                                                                    <p:commandLink value="+ Add" actionListener="#{bean.addAutoComplete()}"                      update=":formName:outerPanel"></p:commandLink>             </div>           </div>      </p:dataList> </h:panelGroup> 

So, the Add button inserts a new item in the list and I update the container panel so that the newly added item can be rendered on the UI.

As expected the panel is updated and I see another autocomplete on the UI. But the problem is, all the auto completes now don't work. i.e. they stop firing the query event and don't give any suggestions.

Edited: The partial response that updates the section of form with autocomplete fields, contains some script tags, which probably execute on page ready/load event. So I know that basically the newly added prime faces widgets are not being initialized.

Any idea how I can initialize the newly added autocompletes in the DOM?

0 Answers

Read More

Monday, May 28, 2018

Disable autocomplete in chrome 66

Leave a Comment

Is there any way to disable autocomplete on a text field in chrome 66? I have tried a number of options like :

  1. autocomplete="off"
  2. autocomplete="false"
  3. autocomplete="disabled"
  4. autocomplete="something-new" etc.

Can anyone help me with this?

Also, one more thing does chrome automatically enables autocomplete for a username if it has a password type field below it?

7 Answers

Answers 1

I used this code and it is working for me. I hope it will also helpful for you. :) Enter your type with readonly and then below mention code.

<input readonly type="email" onfocus="if (this.hasAttribute('readonly')) {     this.removeAttribute('readonly');     this.blur();    this.focus();  }" /> 

Answers 2

Use this

$(document).ready(function(){ $("input").attr("autocomplete", "off"); });

And if the autofill is enabled in chrome you can follow these steps to turn it off:

Turning Off Autofill in Chrome

  1. Click the Chrome menu icon. (Three lines at the top right of your screen.)
  2. Click on Settings.
  3. At the bottom of the page, click “Show Advanced Settings”
  4. In the Passwords and Forms section, uncheck “Enable Autofill to fill out web forms in a single click”

Answers 3

A lot of browsers refuse to adhere to what you have mentioned - the best way is to make an element readonly and then on hover/click/blur/focus, remove readonly.

So you could give it a class such as disable_autocomplete and also make the input field readonly.

Then when the field is hovered, focussed, or clicked you can remove readonly. Optionally, add it back when unfocussed.

Answers 4

$(document).ready(function(){       $("input").val(""); }); 

So, Chrome just sets the value of element when autofilling them. Just try that, else you can try set some interval, wich will check value in HTML code, because Chrome not put new value to HTML code, just puts it in memory for itself.

Answers 5

try this its work in form tag write your html and desings

Answers 6

maybe try

autocomplete="new-password" 

Answers 7

autocomplete="nada"

Tested on Chrome 66 (Windows PC), works OK. Using any values other than "nada" seems to work too, like "nope".

Read More

Wednesday, March 21, 2018

How to call js completion in html file instead of js file?

Leave a Comment

I had installed tern_for_vim and YouCompleteMe for js completion this way.

1 install node

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash source ~/.nvm/nvm.sh nvm install node 

2 install tern_for_vim

$ cd ~/.vim/bundle git clone https://github.com/marijnh/tern_for_vim 

3 install YouCompleteMe

cd ~/.vim/bundle/YouCompleteMe $ ./install.sh --clang-completer --tern-completer 

4 edit .tern-project

vim  .tern-project   {     "libs": [         "browser",         "underscore",         "jquery"     ],     "plugins": {         "node": {}     } } 

Now to vim test.js.
The js completion pop up after inputing document. in test.js file.
enter image description here

Then to vim test.html
No js completion pop up after inputing document. in test.html file.
How to fix it?

2 Answers

Answers 1

Unfortunately this is not officially supported by tern. You can see the response in a closed issue

https://github.com/ternjs/tern_for_vim/issues/170

Because the parsing logic for separating HTML and scripts hasn't been implemented. This could be done as a plugin, if you want to take a shot at it, but it's out of scope for this repository.

But then there is another thread on SO which may help you

Using tern_for_vim plugin in HTML files

So best is to include your code in the html through a JS file and then edit the JS file. Else look at some other plugin/IDE environment. I would explore the below option as well

https://github.com/Shougo/deoplete.nvim#install

Answers 2

I'm unfamiliar with tern_for_vim and YouCompleteMe for js completion, however you could always use vim's built in omni-func completion.

If you add:

filetype on filetype plugin on set omnifunc=syntaxcomplete#Complete 

to your vimrc file, you can then manually set the filetype of your html file to javascript with :set filetype=javascript whilst in vim. Following that, when in insert mode, you can then use <C-x> followed by <C-o> to access javascript language specific omni completion.

The resulting completion menu is then navigable by the standard <C-p> for up and <C-n> for down hotkeys.

This, along with other bits of built in completion functionality are discussed in a nice thoughtbot talk.

Read More

Thursday, February 8, 2018

ASP.NET Core jquery Autocomplete returns blank lines in the list

Leave a Comment

I am using ASP.NET Core jquery Autocomplete with Boostrap 4 I have successfully run the following example from : https://jqueryui.com/autocomplete/

I am now looking to use data from my controller which returns data properly. The result that I get is blank lines.

enter image description here

Here is my Razor page

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">  <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  <div class="ui-widget">     <label>Autocomplete Example: </label>     <input id="LastName" name="LastName" type="text" /> </div> <script>     $("#LastName").autocomplete({         source: '@Url.Action("GetName","Home")'     }); </script> 

Here's my controller [HttpGet] public IActionResult GetName(string term) {

        List<TransactionName> list = new List<TransactionName>()         {              new TransactionName {Id=1,LastName="Linda" },             new TransactionName {Id=2,LastName="Donna" },             new TransactionName {Id=3,LastName="Maryanne" },             new TransactionName {Id=4,LastName="Deb" },             new TransactionName {Id=5,LastName="Liz" },             new TransactionName {Id=6,LastName="Bobby" },             new TransactionName {Id=7,LastName="Beth" }      };         var result = (from N in list                         where N.LastName.Contains(term)                         select new {N.LastName });         return Json(result);     } 

enter image description here

2 Answers

Answers 1

I changed the following based on the jquery Autocomplete documentation:

    var result = (from N in list                     where N.LastName.Contains(term)                     select new {value=N.LastName }); 

Here's a portion of the documentation taken from their site. Multiple types supported: Array: An array can be used for local data. There are two supported formats: An array of strings: [ "Choice1", "Choice2" ] An array of objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]

Answers 2

Your result is returning to your browser as:

{     "Linda",     "Donna",     //... etc } 

What you actually want to return is:

[     "Linda",     "Donna",     //... etc ] 

To do this, simply change your return line to this:

return Json(result.ToArray());

If this does not work, use browser developer tools to inspect your returned result and modify your return line to format the output as the autocomplete method requires.

Read More

Wednesday, November 22, 2017

Semantic UI autocomplete responses arrive out of order

Leave a Comment

I am using the following Semantic UI autocomplete dropdown:

$('.ui.dropdown').dropdown({     minCharacters: 1,     apiSettings: {         url: '/api/people?q={query}'     } }); 

It works, except that when I type 'abc' the responses from my server are returned in the order 'abc', 'ab', 'a' and so the final rendered result is the set of suggestions for 'a', while the field contains 'abc'.

Does Semantic UI provide a standard way to deal with this problem or do I need to implement a fix manually?

2 Answers

Answers 1

The solution would be to cancel previous request whenever new request is made. Semantic UI provides a flag for this (interruptRequests).

$('.ui.dropdown').dropdown({      minCharacters: 1,      apiSettings: {          url: '/api/people?q={query}',          interruptRequests: true      }  });

Ref: https://github.com/Semantic-Org/Semantic-UI/blob/master/RELEASE-NOTES.md

Search for interruptRequest in above link.

Answers 2

You can use match attribute

When using search selection specifies how to match values.

both Matches against text and value

value matches against value only

text matches against text only

The default setting is both

Read More

Wednesday, August 16, 2017

Google Places API - Types different in autocomplete vs detail

Leave a Comment

Given the following API call to autocomplete:

https://maps.googleapis.com/maps/api/place/autocomplete/json?types=address&input=23 norton st

I get the following response:

{     "predictions": [         {             "description": "23 Norton Street, Leichhardt, New South Wales, Australia",             "id": "9711c656faa60f77a05680b603523a4bc75c45be",             "place_id": "EjgyMyBOb3J0b24gU3RyZWV0LCBMZWljaGhhcmR0LCBOZXcgU291dGggV2FsZXMsIEF1c3RyYWxpYQ",             "types": [                 "route",                 "geocode"             ]         },         ...     ],     "status": "OK" } 

Notice the types are of route and geocode. 

If I query the detail API:

https://maps.googleapis.com/maps/api/place/details/json?placeid=EjgyMyBOb3J0b24gU3RyZWV0LCBMZWljaGhhcmR0LCBOZXcgU291dGggV2FsZXMsIEF1c3RyYWxpYQ

I get the following:

{     "html_attributions": [],     "result": {         "id": "e698fdcd9dceed8fe42a926a19cb2b17d4f5f088",         "name": "23 Norton St",         "place_id": "ChIJpdXOTxewEmsRMmpMxLBgFpI",         "reference": "CmRbAAAAKmYoyR1BrFqFQJi6CAD8cjhD4SDnZXMIC0mOLOpX_jPgIgFv0TJ3rv8p5L9xKrplHzUFxBNc8sd7PdkXdnCsTo_7-3X7mocd8yHnXCIKYAxj0MO4icLoFJjD3DEszqK3EhD8XIu6zNH-h3hqotfKjmd-GhRwyNIfJCo4bmOOLYgubm7j8ln_tw",         "scope": "GOOGLE",         "types": [             "street_address"         ],         "url": "https://maps.google.com/?q=23+Norton+St,+Leichhardt+NSW+2040,+Australia&ftid=0x6b12b0174fced5a5:0x921660b0c44c6a32",         "utc_offset": 600,         "vicinity": "Leichhardt"     },     "status": "OK" } 

The types are completely different as well as the place id?!

2 Answers

Answers 1

If you do the search for "23 Norton Street" rather than "23 Norton St" you actually get the results you'd expect (matching place_id, type etc). I think what is happening is that when you search for 23 Norton St it doesn't actually have a match (as St rather than Street) and so it performs a geocode lookup, and that's the result you see.

Is there any reason the result is causing problems for you? Or is it just an oddity/curiosity?

Answers 2

Not sure what your actual issue is, but it is possible for Google Places to actually have multiple IDs for one location. Reference: https://developers.google.com/places/place-id

Also it seems you may have your AutoComplete setup to only provide you back types regarding geocode and route as that is also an option for results. It's unknown without your actual code.

I'm sure you have been to the documentation here: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

but maybe you missed something in the example there. Hope that answers your 'question'!

Read More

Thursday, June 8, 2017

Angucomplete Alt : Getting “No Results Found” before the server response is obtained

Leave a Comment

I am trying to initiate a request after 3 characters but once 3 characters are typed I am getting the No records found error and after that I can find the service call get completed but nothing is shown in auto complete(only the error message under the autocomplete dropdown).What am I missing here?

HTML code:

       <angucomplete-alt id="angu_{{$index}}"                                       placeholder="Search people"                                       remote-api-handler="search"                                       remote-url-data-field="results"                                       title-field="fullName"                                       minlength="3"                                       input-class="form-control form-control-small"                                       selected-object="selected"                                       selected-object-data="$index"                                       clear-selected="true"/> 

Api remote handler

  $scope.search = function(str, timeoutPromise) {    return $timeout(function () {     $scope.input = {};      $scope.input.userId = "";      $scope.input.name = str;      $scope.input.system = "";      $scope.input.officeNumber = "";      $scope.input.department= "";      //  server call and get the response to $scope.organisationNames          var promise = genericAPIService.doApiCall(url, appConstant.POST,       JSON.stringify($scope.input));             promise.then(               function(payload) {                    console.log(payload);                  $scope.organisationNames = payload.data.result.data.List;                  $scope.results = [];                  $scope.organisationNames.forEach(function(organisation) {                         if ((organisation.fullName.toLowerCase().indexOf(str.toString().toLowerCase()) >= 0)) {                             $scope.results.push(organisation);                         }                     });                  return scope.results;               },               function(errorPayload) {                   $log.error('failure loading role json', errorPayload);               }).finally(function(){                      $scope.loading = false;                 });   } },5000); }; 

Tried another version of the same:

 <angucomplete-alt id="angu_{{$index}}"                     placeholder="Search people"                     selected-object="selectedBusiness"                     selected-object-data="$index"                      clear-selected="true"                     input-class="form-control                     form-control-small"                     remote-api-handler="searchAPI"                     remote-url-data-field="responseData.data"                     title-field="fullName" minlength="3" />     $scope.searchAPI = function (userInputString, timeoutPromise) {    $scope.approversAndEndorsersInput = {};    return $timeout(function () {          $scope.approversAndEndorsersInput.userId = "";          $scope.approversAndEndorsersInput.name = userInputString;          $scope.approversAndEndorsersInput.system = "";          $scope.approversAndEndorsersInput.officeNumber = "";          $scope.approversAndEndorsersInput.department= "";          return $http.post(appConstant.selfDomainName+appConstant.getApproversAndEndorsersList, JSON.stringify($scope.approversAndEndorsersInput), {timeout: timeoutPromise});      }, 1000); 

}

3 Answers

Answers 1

First Example

In your first example you never return the promise

var promise = genericAPIService.doApiCall(url, appConstant.POST, ... 

So the $timeout is never resolved with the response from the API
Return the promise at the end of the $timeout callback

Second Example

It looks like that you are not settings correctly the remote-url-data-field

Here's a plunker that I came with using your second example http://plnkr.co/edit/QsJFWh?p=preview and it works correctly, I have slightly altered the searchAPI method to show the last http response

When I misconfigured the remote-url-data-field, the response was made but the angucomplete read "No results found"

See the notes on the plunk, and try to configure it the way it works for you If you can't bind the correct property, provide a response sample from your api, and we can come up with a solution

Using $timeout

The reason you are using $timeout to add a delay is not obvious, you do it in both examples. The only thing this does is to add an artificial delay of the given amount of time. If the reason is to add some debounce/delay to the input field triggering an API request, that won't cut it.

There is a pause property that can be configured with a delay in milliseconds that will ensure that the api will be called after this amount of time when the user has stopped typing. You can see it on the plunker demo, the default value is 500 Since your custom service and $http (from the 2nd example) both return promises, you can directly return their result

Answers 2

I was able to solve the issue.PFB the link which helped in solving it.

Angucomplete-alt: Remote-API-handler not working as expected

Answers 3

Based on what I see in your code, and in the documentation, I think the problem is that you're immediately returning a Promise from $timeout in your searchAPI function, which resolves itself as soon as the timeout is reached. This is why you'll see the "No Records Found" returned, and THEN your API is called. Instead, return your $http promise object directly. i.e.:

$scope.searchAPI = function(userInputString, timeoutPromise) {     // do some other stuff, stringify data, build url_endpoint     return $http.post(url_endpoint, json_data, {timeout: timeoutPromise}); } 

The $http promise will only resolve after your API has been consumed.

Read More

Wednesday, March 1, 2017

JQuery UI Autocomplete not reaching ActionResult C# MVC

Leave a Comment

I have read many posts with the same issue, but none help, so apologies for the duplicate question :( Ive followed the simple sample on the JQueryUI site by hard coding values and the autocomplete works, but I need it to come from my Database.

View:

@Html.TextBoxFor(model => model.Position, new { @type = "text", @id = "jobtitle", @name = "jobtitle", @placeholder = "Job Title" }) 

JS:

EDIT: I added an alert on success, and the alert is being called, but there is no data(i.e. No data being pulled from DB)

<script> $(function () {             $("#jobtitle").autocomplete({                 source: function (request, response) {                     $.ajax({                         url: '@Url.Action("JobsAutoFill", "Account")',                         data: {                             Prefix: request.term                         },                         success: function (data) {                             alert(data);                             response(data);                         }                     });                 },                 minLength: 1             });              //$("#jobtitle").autocomplete({             //    source: "/Account/JobsAutoFill/"             //});         }); </script> 

And I have added the Links required :

<script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 

Below is my ActionResult(Actually a JsonResult) & Function to pull the list of Jobs:

    public List<Jobs> GetAllJobs()     {         List<Jobs> JobsList = new List<Jobs>();          using (RBotEntities EF = new RBotEntities())         {             var JobsListQuery = (from ED in EF.EmploymentDetails                                    select new                                    {                                        ED.pkiEmploymentDetailID,                                        ED.Position                                    });              foreach (var item in JobsListQuery)             {                 JobsList.Add(new Jobs                 {                     Id = item.pkiEmploymentDetailID,                     Name = item.Position                 });             }         }          return JobsList;     }  public JsonResult JobsAutoFill(string Prefix)         {             //Note : you can bind same list from database                 List<Jobs> ObjList = new List<Jobs>();              ObjList = GetAllJobs();              //Searching records from list using LINQ query                 var JobNames = (from N in ObjList                             where N.Name.StartsWith(Prefix)                             select new { N.Name });             return Json(JobNames, JsonRequestBehavior.AllowGet);         } 

Am I missing something or doing something wrong ?

I appreciate any help, thanks!

3 Answers

Answers 1

I got it working!

First thing that was causing an issue was that I needed to add [AllowAnonymous] above my ActionResult.

Secondly, I changed my Ajax call to this:

$(function () {     $("#jobtitle").autocomplete({         source: function (request, response) {             $.ajax({                 url: '@Url.Action("JobsAutoFill", "Account")',                 data: {                     Prefix: request.term                 },                 success: function (data) {                     response($.map(data, function (obj) {                         return {                             label: obj.Name,                             value: obj.Name                         };                     }));                 }             });         },         minLength: 1     }); }); 

Below is my ActionResult. I added a change that would sort out the case sensitivity:

[AllowAnonymous] public JsonResult JobsAutoFill(string Prefix) {     //Note : you can bind same list from database         List<Jobs> ObjList = new List<Jobs>();      ObjList = GetAllJobs();      //Searching records from list using LINQ query         var JobNames = (from N in ObjList                     where N.Name.ToLower().StartsWith(Prefix.ToLower())                     select new { N.Name });     return Json(JobNames, JsonRequestBehavior.AllowGet); } 

Answers 2

You shouldn't make it AllowAnonymous is it doesnt have to be have public access. And secondly change your query for better performance:

var JobNames = (from N in ObjList                 where N.Name.ToLower().StartsWith(Prefix.ToLower())                 select N.Name); 

Obviously you need to return a string array. But your code is returning an object array which has a single string property.

And change your script code acccording to updates:

success: function (data) {                     response($.map(data, function (obj) {                         return {                             label: obj,                             value: obj                         };                     }));                 } 

Answers 3

Dont Change allow to anonymous change your ajax call like that pass your parameter in query string this will hit your back end function. hope this will help you

$(function () { $("#jobtitle").autocomplete({     source: function (request, response) {         $.ajax({             url: '@Url.Action("JobsAutoFill", "Account")?Prefix='+$("#jobtitle").val(),             data: {                 Prefix: request.term             },             success: function (data) {                 response($.map(data, function (obj) {                     return {                         label: obj.Name,                         value: obj.Name                     };                 }));             }         });     },     minLength: 1 }); 

});

Read More

Thursday, March 17, 2016

How to fix IntelliJ IDEA method parameter auto-completion?

Leave a Comment

I am using IntelliJ IDEA 15, and I noticed that (by default) Eclipse offers a much more convenient auto-completion, when it comes to writing method calls, which require multiple parameters.

Eclipse automatically fills in default parameters and allows you to quickly navigate through them by pressing Tab:

enter image description here

However, IntelliJ IDEA does not handle it as conveniently and makes you write them manually:

enter image description here

Is there a way to make IntelliJ IDEA, handle method call auto-completion in a similar way to Eclipse's, and pre-write all the parameters for you, having you just press Tab (or another key) to navigate through them? If it is not possible in original IntelliJ, is there an add-on/plugin/external tool that will improve the IntelliSense in such cases?


Side note: I am not being lazy, it just gets quite annoying, having to manually complete each parameter and put a comma after each one, when IntelliSence should do it for you.

4 Answers

Answers 1

The closest thing to this AFAIK is "method parameter completion", which allows you to auto complete parameters of current method as parameters of the inner method call at once (works for methods and constructors when calling super()).

method parameter completion

Unfortunately the view of Intellij developers is that this feature would be too error prone. See this issue on youtrack.

Answers 2

IDEA doesn't fill the arguments automatically. You can use Ctrl+Shift+Space for auto-completion (completion is based on type, not name) or Ctrl+Alt+Space for suggestion. Or Ctrl+P to see what arguments are accepted.

Answers 3

Try

Ctrl + Space 

for

Basic Code Completion

And like previously was written

Ctrl + Shift + Space 

for

Type Code Completion

or try the second variant TWICE. More about Auto-Completing Code is in here

Answers 4

IntelliJ doesn't do it and AFAIK there isn't a plugin for it.
There is no solution for you (unless you built a plugin yourself, but then you'd just have another job to maintain that plugin)

The alternative is to break the habit/need for it and use IntelliJ's Code Completion shortcuts:

  • Ctrl+P to view possible parameters for function.
  • Ctrl+Shift+Space to list the possible variables that could be entered as a parameter in the respective parameter position (based on type).
    This also enters a comma if another parameter is required for the function.

Hardcoding numbers/strings as parameters to a custom function wouldn't be advisable as that negates the point of the parameters. It's better practice and more common to pass in a pre-defined variable; At which point Ctrl+Shift+Space is the easiest way for Code Completion.
This would also prevent you from closing quotations and adding commas.

Also note: IntelliSense is Microsoft's Intelligent Code Completion implementation which neither IntelliJ nor Eclipse uses.


As frant.hartm states in their answer:

Unfortunately the view of Intellij developers is that this feature would be too error prone. See this issue on youtrack.

They even state that people are welcome to make a plugin that does this.

Read More