Detect same item selection for multiple select/dropdowns with AngularJS

Austin

I am still new with learning all the awesome things Angular can do and one thing I am trying to look at is throwing an ng-invalid if a set of dropdowns have the same item selected.

For example, if I had three selects drop downs, each holding the items: apple, orange, peach. And the user selected apple for drop down 1 and 2, how can I use angular to detect this within the select tag, and throw an ng-invalid?

an example of the current select list I am using are as follows.

<span>
   <select ng-options="champ1.cID as champ1.cName for champ1 in Champions1 | orderBy: 'cName'" ng-init="0" ng-model="champ1">{{champ1.cName}}</select>
</span>
<span>
   <select ng-options="champ2.cID as champ2.cName for champ2 in Champions2 | orderBy: 'cName'" ng-init="0" ng-model="champ2">{{champ2.cName}}</select>
</span>
<span>
   <select ng-options="champ3.cID as champ3.cName for champ3 in Champions3 | orderBy: 'cName'" ng-init="0" ng-model="champ3">{{champ3.cName}}</select>
</span>

Would I use something like ng-if, or toss in some kind of ng-class? I am confused on where/how I would validate in regards to angular without doing some kind of directive or JQuery check.

harishr

you can use ui-validate for custom validations

<select ng-options="champ3.cID as champ3.cName for champ3 in Champions3 | orderBy: 'cName'" 
   ng-init="0" ng-model="champ3" 
   ui-validate="{'same' : 'champ1 == champ3 || champ2 == cmap3'}">
  {{champ3.cName}}
</select>

but above answer only an example. with ui-validate many more custom validations. please read about ui-validate here.

you should read more about forms validations. sample links here/here .

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Detect automatic item selection in a Listbox using Tkinter

From Dev

How to implement multiple item selection?

From Dev

Multiple checkbox selection for list in angularjs

From Dev

iOS: Detect or disable multiple image selection

From Dev

Detect multiple executions of same ksh

From Dev

Trigger ComboBox selection event for the same item

From Dev

Trigger ComboBox selection event for the same item

From Dev

How to detect a selection on JavaFX TableView when clicking a highlighted item?

From Dev

Bootstrap dynamic input selection - multiple on same page

From Dev

Constructor selection for multiple optional parameters of the same type

From Dev

On connectivity selection of multiple wifi routers in the same LAN

From Dev

select same parents in multiple Tournament selection

From Dev

AngularJS - Multiple keypress at the same time

From Dev

Angularjs multiple urls for same state

From Dev

AngularJS - Multiple keypress at the same time

From Dev

Angularjs select: How to get the position of the selected item and set default selection

From Dev

GIMP Python, selection based on path not the same as menu item "From Path"

From Dev

Handle multiple item in single controller? AngularJS

From Dev

Count item across multiple columns in same table

From Dev

Search with multiple range values on same item

From Dev

Recycling views shows same item multiple times

From Dev

Microdata itemref - multiple references to the same item

From Dev

Count item across multiple columns in same table

From Dev

Multiple textboxes fill the dropdown selection having same class in jquery

From Dev

Eclipse - How to set multiple viewers as selection providers from the same page

From Dev

Index selection behaviour in oracle in case of multiple indexes on same columns

From Dev

What rule arranges the selection grid for multiple windows of the same program?

From Dev

Insert same ID connected to multiple selection options ID

From Dev

Multiple textboxes fill the dropdown selection having same class in jquery

Related Related

  1. 1

    Detect automatic item selection in a Listbox using Tkinter

  2. 2

    How to implement multiple item selection?

  3. 3

    Multiple checkbox selection for list in angularjs

  4. 4

    iOS: Detect or disable multiple image selection

  5. 5

    Detect multiple executions of same ksh

  6. 6

    Trigger ComboBox selection event for the same item

  7. 7

    Trigger ComboBox selection event for the same item

  8. 8

    How to detect a selection on JavaFX TableView when clicking a highlighted item?

  9. 9

    Bootstrap dynamic input selection - multiple on same page

  10. 10

    Constructor selection for multiple optional parameters of the same type

  11. 11

    On connectivity selection of multiple wifi routers in the same LAN

  12. 12

    select same parents in multiple Tournament selection

  13. 13

    AngularJS - Multiple keypress at the same time

  14. 14

    Angularjs multiple urls for same state

  15. 15

    AngularJS - Multiple keypress at the same time

  16. 16

    Angularjs select: How to get the position of the selected item and set default selection

  17. 17

    GIMP Python, selection based on path not the same as menu item "From Path"

  18. 18

    Handle multiple item in single controller? AngularJS

  19. 19

    Count item across multiple columns in same table

  20. 20

    Search with multiple range values on same item

  21. 21

    Recycling views shows same item multiple times

  22. 22

    Microdata itemref - multiple references to the same item

  23. 23

    Count item across multiple columns in same table

  24. 24

    Multiple textboxes fill the dropdown selection having same class in jquery

  25. 25

    Eclipse - How to set multiple viewers as selection providers from the same page

  26. 26

    Index selection behaviour in oracle in case of multiple indexes on same columns

  27. 27

    What rule arranges the selection grid for multiple windows of the same program?

  28. 28

    Insert same ID connected to multiple selection options ID

  29. 29

    Multiple textboxes fill the dropdown selection having same class in jquery

HotTag

Archive