Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -384,6 +384,16 @@ |
385 | 385 | return $value; |
386 | 386 | } |
387 | 387 | |
| 388 | + /** |
| 389 | + * Should this field have a label, or is there no input element with the |
| 390 | + * appropriate id for the label to point to? |
| 391 | + * |
| 392 | + * @return bool True to output a label, false to suppress |
| 393 | + */ |
| 394 | + protected function needsLabel() { |
| 395 | + return true; |
| 396 | + } |
| 397 | + |
388 | 398 | function loadDataFromRequest( $request ) { |
389 | 399 | if( $request->getCheck( $this->mName ) ) { |
390 | 400 | return $request->getText( $this->mName ); |
— | — | @@ -455,8 +465,14 @@ |
456 | 466 | |
457 | 467 | $html = ''; |
458 | 468 | |
| 469 | + # Don't output a for= attribute for labels with no associated input. |
| 470 | + # Kind of hacky here, possibly we don't want these to be <label>s at all. |
| 471 | + $for = array(); |
| 472 | + if ( $this->needsLabel() ) { |
| 473 | + $for['for'] = $this->mID; |
| 474 | + } |
459 | 475 | $html .= Html::rawElement( 'td', array( 'class' => 'mw-label' ), |
460 | | - Html::rawElement( 'label', array( 'for' => $this->mID ), $this->getLabel() ) |
| 476 | + Html::rawElement( 'label', $for, $this->getLabel() ) |
461 | 477 | ); |
462 | 478 | $html .= Html::rawElement( 'td', array( 'class' => 'mw-input' ), |
463 | 479 | $this->getInputHTML( $value ) ."\n$errors" ); |
— | — | @@ -837,6 +853,10 @@ |
838 | 854 | return array(); |
839 | 855 | } |
840 | 856 | } |
| 857 | + |
| 858 | + protected function needsLabel() { |
| 859 | + return false; |
| 860 | + } |
841 | 861 | } |
842 | 862 | |
843 | 863 | class HTMLRadioField extends HTMLFormField { |
— | — | @@ -886,6 +906,10 @@ |
887 | 907 | |
888 | 908 | return $html; |
889 | 909 | } |
| 910 | + |
| 911 | + protected function needsLabel() { |
| 912 | + return false; |
| 913 | + } |
890 | 914 | } |
891 | 915 | |
892 | 916 | class HTMLInfoField extends HTMLFormField { |
— | — | @@ -906,4 +930,8 @@ |
907 | 931 | |
908 | 932 | return parent::getTableRow( $value ); |
909 | 933 | } |
| 934 | + |
| 935 | + protected function needsLabel() { |
| 936 | + return false; |
| 937 | + } |
910 | 938 | } |