@@ -42,6 +42,12 @@ export class SelectionModel extends Observable {
4242 super ( ) ;
4343 const { availableOptions = [ ] , defaultSelection = [ ] , multiple = true , allowEmpty = true } = configuration || { } ;
4444
45+ /**
46+ * @type {SelectionOption[] }
47+ * @protected
48+ */
49+ this . _selectionBacklog = [ ] ;
50+
4551 /**
4652 * @type {RemoteData<SelectionOption[]>|SelectionOption[] }
4753 * @protected
@@ -243,14 +249,20 @@ export class SelectionModel extends Observable {
243249 }
244250
245251 /**
246- * Defines the list of available options
252+ * Defines the list of available options and if there is a selection backlog, these will be applied
247253 *
248254 * @param {RemoteData<SelectionOption[], *>|SelectionOption[] } availableOptions the new available options
249255 * @return {void }
250256 */
251257 setAvailableOptions ( availableOptions ) {
252258 this . _availableOptions = availableOptions ;
253259 this . visualChange$ . notify ( ) ;
260+
261+ if ( this . _selectionBacklog . length ) {
262+ this . selectedOptions = this . _selectionBacklog ;
263+ this . _selectionBacklog = [ ] ;
264+ this . notify ( ) ;
265+ }
254266 }
255267
256268 /**
@@ -315,12 +327,19 @@ export class SelectionModel extends Observable {
315327 }
316328
317329 /**
318- * Define (overrides) the list of currently selected options
330+ * Define (overrides) the list of currently selected options.
331+ * Invalid selection options are excluded
319332 *
320333 * @param {SelectionOption[] } selected the list of selected options
321334 */
322335 set selectedOptions ( selected ) {
323- this . _selectedOptions = selected ;
336+ let { options } = this ;
337+
338+ if ( this . options instanceof RemoteData ) {
339+ options = options . isSuccess ( ) ? options . payload : [ ] ;
340+ }
341+
342+ this . _selectedOptions = options . filter ( ( option ) => selected . some ( ( { value } ) => String ( value ) === String ( option . value ) ) ) ; ;
324343 }
325344
326345 /**
@@ -332,6 +351,23 @@ export class SelectionModel extends Observable {
332351 return this . _defaultSelection ;
333352 }
334353
354+ /**
355+ * Sets selected options based on a comma-seperated string.
356+ * Accounts for the options being either RemoteData or an array.
357+ *
358+ * @return {string }
359+ */
360+ set normalized ( value ) {
361+ const options = value . split ( ',' ) . map ( ( option ) => ( { value : option } ) ) ;
362+ const postponeSelection = this . options instanceof RemoteData || ! this . options ?. length ;
363+
364+ if ( postponeSelection ) {
365+ this . _selectionBacklog = options ;
366+ } else {
367+ this . selectedOptions = options ;
368+ }
369+ }
370+
335371 /**
336372 * Returns the normalized value of the selection
337373 *
0 commit comments