| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * A combo box field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * You can think of it as a dropdown select with the ability to add custom options, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * or as a text field with input suggestions (autocompletion). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * When JavaScript is not supported or enabled, it uses HTML5 `<datalist>` element. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Besides the parameters recognized by HTMLTextField, the following are | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * recognized: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  *   options-messages - As for HTMLSelectField | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  *   options - As for HTMLSelectField | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  *   options-message - As for HTMLSelectField | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | class HTMLComboboxField extends HTMLTextField { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | 	// FIXME Ewww, this shouldn't be adding any attributes not requested in $list :( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	public function getAttributes( array $list ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$attribs = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 			'type' => 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 			'list' => $this->mName . '-datalist', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		] + parent::getAttributes( $list ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		return $attribs; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 26 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	function getInputHTML( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		$datalist = new XmlSelect( false, $this->mName . '-datalist' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		$datalist->setTagName( 'datalist' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		$datalist->addOptions( $this->getOptions() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		return parent::getInputHTML( $value ) . $datalist->getHTML(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 36 |  | View Code Duplication | 	function getInputOOUI( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		$disabled = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		$allowedParams = [ 'tabindex' ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		$attribs = OOUI\Element::configFromHtmlAttributes( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			$this->getAttributes( $allowedParams ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		if ( $this->mClass !== '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			$attribs['classes'] = [ $this->mClass ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		if ( !empty( $this->mParams['disabled'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			$disabled = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		return new OOUI\ComboBoxInputWidget( [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			'name' => $this->mName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			'id' => $this->mID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			'options' => $this->getOptionsOOUI(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			'value' => strval( $value ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			'disabled' => $disabled, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		] + $attribs ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	protected function shouldInfuseOOUI() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		return true; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 63 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |  |