Display all rows in proposalfield [message #1839503] |
Tue, 23 March 2021 02:43 |
Pr Nico Messages: 23 Registered: February 2021 |
Junior Member |
|
|
Hello, I am trying to setup the autocomplete feature from google maps in a proposal field.
I would to modify my field so the propositions are always refreshed and displayed even if it does not fit exactly what I type, let's say like a droplist.
So for instance if the user type "15 rue de Crimee paris", "15 rue de Crimée, Paris, France" would be proposed as a choice.
What I managed to do so far is this :
The tricky part is when what I type do not exactly match the value, example the real name of the street is "Crimée", but the user input "Crime"
The Google API is smart enough to guess what the user wants to type, even with spelling mistake, so I can load this in my rowList :
@Order(4500)
public class MyAdresseSmartField extends AbstractProposalField<String> {
@Override
protected String getConfiguredLabel() {
return TEXTS.get("Adressev2");
}
@Override
protected void execInitField() {
token = new PlaceAutocompleteRequest.SessionToken();
super.execInitField();
}
@Override
protected void lookupByTextInternal(String text, boolean synchronous) {
List<LookupRow<String>> rows = new ArrayList<>();
//...
//loading rows from api using text variable ((AdresseValidationLookupCall)this.getLookupCall()).setLookupRows(rows);
super.lookupByTextInternal(text, synchronous);
}
@Override
protected Class<? extends ILookupCall<String>> getConfiguredLookupCall() {
return (Class<? extends ILookupCall<String>>) AdresseValidationLookupCall.class;
}
@Override
public boolean isSearchRequired() {
return true;
}
}
Maybe what I am trying to do is against the essence of smart field, if that is the case let me know and I will try to create a js widget instead.
Amazing work on version 11 :)
[Updated on: Tue, 23 March 2021 12:21] Report message to a moderator
|
|
|
Re: Display all rows in proposalfield [message #1839534 is a reply to message #1839503] |
Tue, 23 March 2021 12:52 |
|
Hi Nico
I'd recommend not to override Scout methods named "internal", as they are not part of the public API and may change any time. Instead use the concept outlined here: https://eclipsescout.github.io/11.0/technical-guide.html#lookup-call
The "AdresseValidationLookupCall" is a good start, but I'd recommend to implement a dedicated service that does the lookup work and calls the Google API.
Reference that service in your LookupCall class. Dummy code:
public class AdresseValidationLookupCall extends LookupCall<String> {
@Override
protected Class<? extends ILookupService<String>> getConfiguredService() {
return IAdresseValidationLookupService.class;
}
}
Then implement the service class like this. In your case the important method here is getDataByText, which will receive the search query the user has typed into the proposal field and returns the collection of lookup rows to be displayed in the UI.
public class AdresseValidationLookupService implements IAdresseValidationLookupService {
@Override
public List<? extends ILookupRow<String>> getDataByText(ILookupCall<String> call0) {
// your code to call google here...
}
// other lookup methods... if required
}
Hope that helps. Cheers,
André
Eclipse Scout Homepage | Documentation | GitHub
[Updated on: Wed, 24 March 2021 06:44] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03348 seconds