Rev | Line | |
---|
[1227] | 1 | package gov.va.med.edp.view.config
|
---|
| 2 | {
|
---|
| 3 | import gov.va.med.edp.vo.RoomBedVO;
|
---|
| 4 |
|
---|
| 5 | import mx.collections.ArrayCollection;
|
---|
| 6 | import mx.validators.ValidationResult;
|
---|
| 7 | import mx.validators.Validator;
|
---|
| 8 |
|
---|
| 9 | public class DuplicateNameValidator extends Validator
|
---|
| 10 | {
|
---|
| 11 | [Bindable]
|
---|
| 12 | public var beds:ArrayCollection;
|
---|
| 13 |
|
---|
| 14 | [Bindable]
|
---|
| 15 | public var selectedBed:RoomBedVO;
|
---|
| 16 |
|
---|
| 17 | [Bindable]
|
---|
| 18 | public var field:String;
|
---|
| 19 |
|
---|
| 20 | private var results:Array;
|
---|
| 21 |
|
---|
| 22 | public function DuplicateNameValidator() {
|
---|
| 23 | super();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | private function isDuplicate(value:String):Boolean {
|
---|
| 27 | if (selectedBed == null) return false;
|
---|
| 28 | var skipIndex:int = beds.getItemIndex(selectedBed);
|
---|
| 29 | for (var i:int = 0; i < beds.length; i++) {
|
---|
| 30 | if (i == skipIndex) continue;
|
---|
| 31 | var bed:RoomBedVO = beds[i] as RoomBedVO;
|
---|
| 32 |
|
---|
| 33 | if (bed[field].toLowerCase() == value.toLowerCase()) return true;
|
---|
| 34 | }
|
---|
| 35 | return false;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | override protected function doValidation(value:Object):Array {
|
---|
| 39 | var inputValue:String = String(value);
|
---|
| 40 |
|
---|
| 41 | results = [];
|
---|
| 42 | results = super.doValidation(value);
|
---|
| 43 | if (results.length > 0)
|
---|
| 44 | return results;
|
---|
| 45 |
|
---|
| 46 | if (isDuplicate(inputValue)) {
|
---|
| 47 | results.push(new ValidationResult(true, null, "duplicate", "Duplicate name is not allowed."));
|
---|
| 48 | return results;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | return results;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.