public/javascripts/inputex/js/fields/SelectTwiceField.js
function () {
			
			var i, j, ilength, jlength, currentSubChoices, currentSubChoice, currentValue,
			    testValue, isDuplicateChoice, secondSelectChoices;
			
			
			// object used in updateSecondSelectChoices
			//
			//   * key   : string representing a value in 1st select
			//   * value : array of values available in 2nd select when key is selected in first select
			//
			this.valuesMatching = {};
			
			
			// helper to filter 2nd select choices to find duplicates
			isDuplicateChoice = function(elt, arrElt) {
				elt    = lang.isObject(elt)    ? elt.value    : elt;
				arrElt = lang.isObject(arrElt) ? arrElt.value : arrElt;
				return elt === arrElt;
			};
			
			// collect 2nd level choices + ensure uniqueness of values
			secondSelectChoices = [];
			
			for (i = 0, ilength = this.options.choices.length; i < ilength; i += 1) {
				
				currentValue = lang.isObject(this.options.choices[i]) ? this.options.choices[i].value : this.options.choices[i];
				currentSubChoices = this.options.choices[i].choices;
				
				this.valuesMatching[currentValue] = [];
				
				// maybe no sub choices ???
				if (currentSubChoices) {
					for (j = 0, jlength = currentSubChoices.length; j < jlength; j += 1) {
					
						currentSubChoice = currentSubChoices[j];
					
						testValue = lang.isObject(currentSubChoice) ? currentSubChoice.value : currentSubChoice;
					
						this.valuesMatching[currentValue].push(testValue);
					
						if (inputEx.indexOf(testValue, secondSelectChoices, isDuplicateChoice) === -1) {
							secondSelectChoices.push(currentSubChoices[j]);
						}
					
					}
				}
				
			}
			
			
			// create and store selects
			this.selects = [];
			this.selects.push(new inputEx.SelectField({ choices: this.options.choices }));
			this.selects.push(new inputEx.SelectField({ choices: secondSelectChoices }));
			
			// append <select>s to DOM tree
			this.fieldContainer.appendChild(this.selects[0].getEl());
			this.fieldContainer.appendChild(this.selects[1].getEl());
			
		}
function () {
			
			var i, j, ilength, jlength, currentSubChoices, currentSubChoice, currentValue,
			    testValue, isDuplicateChoice, secondSelectChoices;
			
			
			// object used in updateSecondSelectChoices
			//
			//   * key   : string representing a value in 1st select
			//   * value : array of values available in 2nd select when key is selected in first select
			//
			this.valuesMatching = {};
			
			
			// helper to filter 2nd select choices to find duplicates
			isDuplicateChoice = function(elt, arrElt) {
				elt    = lang.isObject(elt)    ? elt.value    : elt;
				arrElt = lang.isObject(arrElt) ? arrElt.value : arrElt;
				return elt === arrElt;
			};
			
			// collect 2nd level choices + ensure uniqueness of values
			secondSelectChoices = [];
			
			for (i = 0, ilength = this.options.choices.length; i < ilength; i += 1) {
				
				currentValue = lang.isObject(this.options.choices[i]) ? this.options.choices[i].value : this.options.choices[i];
				currentSubChoices = this.options.choices[i].choices;
				
				this.valuesMatching[currentValue] = [];
				
				// maybe no sub choices ???
				if (currentSubChoices) {
					for (j = 0, jlength = currentSubChoices.length; j < jlength; j += 1) {
					
						currentSubChoice = currentSubChoices[j];
					
						testValue = lang.isObject(currentSubChoice) ? currentSubChoice.value : currentSubChoice;
					
						this.valuesMatching[currentValue].push(testValue);
					
						if (inputEx.indexOf(testValue, secondSelectChoices, isDuplicateChoice) === -1) {
							secondSelectChoices.push(currentSubChoices[j]);
						}
					
					}
				}
				
			}
			
			
			// create and store selects
			this.selects = [];
			this.selects.push(new inputEx.SelectField({ choices: this.options.choices }));
			this.selects.push(new inputEx.SelectField({ choices: secondSelectChoices }));
			
			// append <select>s to DOM tree
			this.fieldContainer.appendChild(this.selects[0].getEl());
			this.fieldContainer.appendChild(this.selects[1].getEl());
			
		}
function ( ) { var i , j , ilength , jlength , currentSubChoices , currentSubChoice , currentValue , testValue , isDuplicateChoice , secondSelectChoices ; // object used in updateSecondSelectChoices // //   * key   : string representing a value in 1st select //   * value : array of values available in 2nd select when key is selected in first select // this . valuesMatching = { } ; // helper to filter 2nd select choices to find duplicates isDuplicateChoice = function ( elt , arrElt ) { elt = lang . isObject ( elt ) ? elt . value : elt ; arrElt = lang . isObject ( arrElt ) ? arrElt . value : arrElt ; return elt === arrElt ; } ; // collect 2nd level choices + ensure uniqueness of values secondSelectChoices = [ ] ; for ( i = 0 , ilength = this . options . choices . length ; i < ilength ; i += 1 ) { currentValue = lang . isObject ( this . options . choices [ i ] ) ? this . options . choices [ i ] . value : this . options . choices [ i ] ; currentSubChoices = this . options . choices [ i ] . choices ; this . valuesMatching [ currentValue ] = [ ] ; // maybe no sub choices ??? if ( currentSubChoices ) { for ( j = 0 , jlength = currentSubChoices . length ; j < jlength ; j += 1 ) { currentSubChoice = currentSubChoices [ j ] ; testValue = lang . isObject ( currentSubChoice ) ? currentSubChoice . value : currentSubChoice ; this . valuesMatching [ currentValue ] . push ( testValue ) ; if ( inputEx . indexOf ( testValue , secondSelectChoices , isDuplicateChoice ) === - 1 ) { secondSelectChoices . push ( currentSubChoices [ j ] ) ; } } } } // create and store selects this . selects = [ ] ; this . selects . push ( new inputEx . SelectField ( { choices : this . options . choices } ) ) ; this . selects . push ( new inputEx . SelectField ( { choices : secondSelectChoices } ) ) ; // append <select>s to DOM tree this . fieldContainer . appendChild ( this . selects [ 0 ] . getEl ( ) ) ; this . fieldContainer . appendChild ( this . selects [ 1 ] . getEl ( ) ) ; }
Build two select fields
Build two select fields