@@ -49,6 +49,10 @@ Wpt.form.initQuestionAnswered = function(form) {
4949 } ) . bind ( 'question_unanswered_initially.wpt' , function ( event , question ) {
5050 question . removeClass ( 'answered' ) ;
5151 question . find ( '.answer input:first' ) . attr ( 'required' , 'required' ) . attr ( 'aria-required' , 'true' ) ;
52+ } ) . bind ( 'answer_selected.wpt' , function ( event , answer ) {
53+ answer . addClass ( 'selected' ) ;
54+ } ) . bind ( 'answer_unselected.wpt' , function ( event , answer ) {
55+ answer . removeClass ( 'selected' ) ;
5256 } ) ;
5357} ;
5458
@@ -146,7 +150,19 @@ Wpt.form.setupQuestionsAnswered = function($, form) {
146150 question . find ( '.answer' ) . each ( function ( ) {
147151 var answer = $ ( this ) ;
148152 answer . find ( 'input' ) . bind ( 'change' , function ( ) {
149- if ( ! $ ( this ) . attr ( 'checked' ) ) {
153+ answer . data ( 'isSelected' , ! ! $ ( this ) . attr ( 'checked' ) ) ;
154+ if ( answer . data ( 'isSelected' ) ) {
155+ form . trigger ( 'answer_selected.wpt' , [ answer ] ) ;
156+ questionAnswersInputs . each ( function ( i , otherInput ) {
157+ var $el = $ ( otherInput ) ;
158+ if ( $el . closest ( '.answer' ) . data ( 'isSelected' ) != ! ! $ ( otherInput ) . attr ( 'checked' ) ) {
159+ $el . change ( ) ;
160+ }
161+ } ) ;
162+ } else {
163+ form . trigger ( 'answer_unselected.wpt' , [ answer ] ) ;
164+ }
165+ if ( ! answer . data ( 'isSelected' ) ) {
150166 var isAllCheckboxesEmpty = ( 0 == questionAnswersInputs . filter ( ':checked' ) . length ) ;
151167 if ( isAllCheckboxesEmpty ) {
152168 question . data ( 'isAnswered' , false ) ;
0 commit comments