Selecting One at a time validation

22 views
Skip to first unread message

simhadri....@snl.com

unread,
Jan 18, 2017, 7:54:44 AM1/18/17
to KnockoutJS
Multi-select drop-down list: I have below requirement 
Both Alpha and Beta Cannot be selected. Only one should be selected at a time.
Let say I have selected Alpha and then Continuing to select Beta Then Alpha should be unchecked and beta should be selected. The same goes vice versa.
 Do we have any solution using knockout js for this problem?

noirabys

unread,
Jan 18, 2017, 9:03:59 AM1/18/17
to KnockoutJS
hi,

so you want a multiselect box to be singlechoice only ?

i guess that it is not recommended because of user experience, but a hacky way might be:

add a subscribe to the result array with "beforeChange" option and reset the underlying array ?!


ko.contextFor($('select')[0]).$root.multipleSelectedOptionValues.subscribe(function(newVal){ this().splice(0,this().length);},ko.contextFor($('select')[0]).$root.multipleSelectedOptionValues,"beforeChange");

best regards,
  noirabys


btw there seems to be an error on the page:

Uncaught Error: Syntax error, unrecognized expression: .main-menu a[rel=]

Gunnar Liljas

unread,
Jan 18, 2017, 9:23:37 AM1/18/17
to knock...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages