Skip to content

Commit 8c26fa3

Browse files
committed
Over-clarify the workings of asyncCallback
1 parent 3be3948 commit 8c26fa3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ Like strapselectdynamic above, but allowed multiple items to be selected.
220220
```
221221
### Multiple select from asynchronous callback
222222

223-
The asyncCallback must return a http-style promise and the data must be a JSON array of value/name objects.
224-
Note that in this example, the reference to the callback is a string, meaning a callback in the using controller scope.
223+
The asyncCallback must return a *http-style promise* and the data the promise provides must be a JSON array of value/name objects.
224+
225+
225226
```js
226227
{
227228
"key": "multiselectDynamicAsync",
@@ -233,6 +234,10 @@ Note that in this example, the reference to the callback is a string, meaning a
233234
}
234235
},
235236
```
237+
Note that in this example, the reference to the callback is a string, meaning a callback in the using controller scope.
238+
Also note, again, because this is a common misunderstanding, that asyncCallback should *not* return the array of items, but a http-promise, like the one $http.get()/$http.post()
239+
Returning the array would be a synchronous operation, see "callback" above.
240+
236241
### Multiple select from dynamically loaded list via http get
237242
Convenience function, makes a get request, no need for callback.
238243
Expects the server to return a JSON array of value/name objects.
@@ -443,7 +448,7 @@ The two kinds of callback mechanisms are:
443448

444449
* list items are fetched by a user-specified callback. The user implements the calling mechanism.
445450
* the callback receive the form options as a parameter and returns an array of list items(see the static strapselect)
446-
* asyncCallback implementations returns the data through a HttpPromise.
451+
* asyncCallback implementations returns the data through a HttpPromise. NOT an array if items.
447452

448453
*TIP: in an asyncCallback, you need to intercept and change an async server response before passing it on to the add-on, use the [transformResponse function](https://docs.angularjs.org/api/ng/service/$http#transforming-requests-and-responses).*
449454

0 commit comments

Comments
 (0)