@@ -28,8 +28,12 @@ <h3>{{.title}}</h3>
2828 {{ $visibilityCondition := "" }}
2929 {{ range .visible_when_or }}
3030 {{ range .visible_when_and }}
31+ {{ $compareSign := "==" }}
32+ {{ if .compareSign }}
33+ {{ $compareSign = .compareSign }}
34+ {{ end }}
3135 {{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" .value | printf "%s" }}
32- {{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" "=" | printf "%s" }}
36+ {{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" $compareSign | printf "%s" }}
3337 {{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" .identifier | printf "%s" }}
3438 {{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" "&&" | printf "%s" }}
3539 {{ end }}
@@ -166,8 +170,12 @@ <h6 class="d-inline ml-1" >{{.title}}</h6>
166170< script >
167171 document . addEventListener ( "DOMContentLoaded" , function ( event ) {
168172
173+ var valuesAreEqual = function ( inputValue , value ) {
174+ return inputValue === value || ( value === '*' && inputValue ) ;
175+ }
176+
169177 var calculateVisibleFields = function ( ) {
170- // this is what the data attribute looks like: data-show-when="||&&data1=medium&&data2=medium||&&data1=low"
178+ // this is what the data attribute looks like: data-show-when== "||&&data1== medium&&data2=medium||&&data1= =low"
171179 // This field should be hidden when no input is selected, and shown if either data 1 and data 2 are medium or data 1 is low.
172180 $ ( '.score-card__question' ) . each ( function ( ) {
173181 const showWhen = $ ( this ) . attr ( 'data-show-when' ) ;
@@ -183,14 +191,26 @@ <h6 class="d-inline ml-1" >{{.title}}</h6>
183191 if ( andCondition . indexOf ( '=' ) === - 1 ) {
184192 return ;
185193 }
186- const [ name , value ] = andCondition . split ( '=' ) ;
194+ // And condition can be either a==b or a!=b
195+ const andCondSplitted = andCondition . split ( '=' ) ;
196+ let name = andCondSplitted [ 0 ] ;
197+ let value = andCondSplitted [ andCondSplitted . length - 1 ] ;
198+ const checkForEquals = andCondSplitted . length > 2 ;
199+ const checkForUnequal = ! checkForEquals ;
200+ if ( ! checkForEquals ) {
201+ // clean up name when name is a!
202+ name = name . substring ( 0 , name . length - 1 ) ;
203+ }
204+
187205 // Check for radio button
188206 let input = document . querySelector ( `.score-card__question:not(.d-none) input[name=${ name } ]:checked` ) ;
189207 // Check for checkbox
190208 if ( ! input ) {
191209 input = document . querySelector ( `.score-card__question:not(.d-none) input[id=${ name } ]:checked` ) ;
192210 }
193- if ( ! input || input . value !== value ) {
211+ if ( ! input
212+ || ( checkForEquals && ! valuesAreEqual ( input . value , value ) )
213+ || ( checkForUnequal && valuesAreEqual ( input . value , value ) ) ) {
194214 andShow = false ;
195215 }
196216 } ) ;
0 commit comments