-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFR] Send API request on reference auto-complete #508
Conversation
|
||
return ReadQueries.getAllReferencedData(referenceFields, search) | ||
.then(r => r[field.name()]) | ||
.then((results) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need parentheses for a single argument
Switching to RFR. I still need to test it on a real world project before merging. |
890aa93
to
f4e695d
Compare
Tested on real world project. Seems to work. Removing the [DO NOT MERGE]. |
} | ||
scope.getChoices = typeof(choices) === 'function' ? choices : function() { return choices; }; | ||
var choices = field.choices(); | ||
scope.choices = typeof(choices) === 'function' ? choices(scope.entry) : choices; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this works, I had to return a function because Angular complained about an infinite look. Needs further testing.
If you have to put some API fetching logic in a directive, please move it to a service. |
expect(uiSelect).toBeTruthy(); | ||
}); | ||
|
||
it('should call remote API when inputting first characters', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something bothers me: users can't opt out for ajax autocompletion. That means that if their API doesn't implement the search query param, reference fields cease to work. This is a serious BC break.
Autocomplete should be opt-in ; the default behavior should still be to fetch all possible values, and only autocomplete locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is already dealt through the field.refreshDelay
parameter. If it's null, then all choices would be retrieved, the same as before my changes.
I put the API request behavior by default, as it sounds more logical to me for references. Indeed, user doesn't know how many records there is remotely. And it is more probable that there is a lot. It would then be limited by the perPage
parameter.
This is indeed a BC break, but it improves the component behavior IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As seen with @fzaninotto, we'll set refreshDelay
to null by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, you must make it more explicit that in the doc that a Reference is populated by the entire list of references, and that if the developer wants to use autocomplete, they should set the refreshdelay to something more than null.
Refresh logic moved to a dedicated service. Ready for another review. |
Is it possible to disable first request (in routing) for retrieving references values in case of |
Back to WIP for optimizing number of sent requests and to fix autocomplete, which seems to be made only on local records. |
Ready for review. Failing tests are due to the admin-config PR. |
👍 |
[RFR] Send API request on reference auto-complete
Great work, thanks a lot! |
Hey guys! Is there any way to get the Check out this example:
What could I do? |
@endel: not for now. But this |
Instead of having a pre-define set of choices in reference fields, send API requests at will to fetch related records.
Left tasks:
refreshDelay