@@ -12,7 +12,7 @@ import { field, mostSpecificClassURI, fieldFunction } from './forms/fieldFunctio
1212import { setFieldStyle } from './forms/formStyle'
1313import * as debug from '../debug'
1414import { errorMessageBlock } from './error'
15- import { basicField } from './forms/basic'
15+ import { basicField , renderNameValuePair } from './forms/basic'
1616import { autocompleteField } from './forms/autocomplete/autocompleteField'
1717import * as style from '../style'
1818
@@ -172,27 +172,32 @@ field[ns.ui('Options').uri] = function (
172172 }
173173 let values
174174 if ( dependingOn . sameTerm ( ns . rdf ( 'type' ) ) ) {
175- values = kb . findTypeURIs ( subject )
175+ values = Object . keys ( kb . findTypeURIs ( subject ) ) . map ( uri => $rdf . sym ( uri ) ) // Use RDF-S inference
176176 } else {
177- const value = kb . any ( subject , dependingOn )
178- if ( value === undefined ) {
179- box . appendChild (
180- errorMessageBlock (
181- dom ,
182- "Can't select subform as no value of: " + dependingOn
183- )
184- )
185- } else {
186- values = { }
187- values [ value . uri ] = true
188- }
177+ values = kb . each ( subject , dependingOn )
189178 }
190- // @@ Add box.refresh() to sync fields with values
191- for ( let i = 0 ; i < cases . length ; i ++ ) {
192- const c = cases [ i ]
193- const tests = kb . each ( c , ui ( 'for' ) , null , formDoc ) // There can be multiple 'for'
194- for ( let j = 0 ; j < tests . length ; j ++ ) {
195- if ( values [ tests [ j ] . uri ] ) {
179+ if ( values . length === 0 ) {
180+ box . appendChild (
181+ errorMessageBlock (
182+ dom ,
183+ "Can't select subform as no value of: " + dependingOn
184+ )
185+ )
186+ } else {
187+ for ( let i = 0 ; i < cases . length ; i ++ ) {
188+ const c = cases [ i ]
189+ const tests = kb . each ( c , ui ( 'for' ) , null , formDoc ) // There can be multiple 'for'
190+ let match = false
191+ for ( let j = 0 ; j < tests . length ; j ++ ) {
192+ for ( const value of values ) {
193+ const test = tests [ j ]
194+ if ( value . sameTerm ( tests ) ||
195+ ( value . termType === test . termType && value . value === test . value ) ) {
196+ match = true
197+ }
198+ }
199+ }
200+ if ( match ) {
196201 const field = kb . the ( c , ui ( 'use' ) )
197202 if ( ! field ) {
198203 box . appendChild (
@@ -217,6 +222,7 @@ field[ns.ui('Options').uri] = function (
217222 }
218223 }
219224 }
225+ // @@ Add box.refresh() to sync fields with values
220226 return box
221227}
222228
@@ -1579,20 +1585,14 @@ export function makeSelectForNestedCategory (
15791585 */
15801586export function buildCheckboxForm ( dom , kb , lab , del , ins , form , dataDoc , tristate ) {
15811587 const box = dom . createElement ( 'div' )
1582- const tx = dom . createTextNode ( lab )
1588+ const rhs = renderNameValuePair ( dom , kb , box , form )
15831589 const editable = kb . updater . editable ( dataDoc . uri )
1584- tx . style = style . checkboxStyle
1585-
1586- box . appendChild ( tx )
1587- let input
1588- // eslint-disable-next-line prefer-const
1589- input = dom . createElement ( 'button' )
15901590
1591- input . setAttribute (
1592- 'style' ,
1593- 'font-size: 150%; height: 1.2em; width: 1.2em; background-color: #eef; margin: 0.1em'
1594- )
1595- box . appendChild ( input )
1591+ const input = dom . createElement ( 'button' )
1592+ const colorCarrier = input // Which element changes color to flag changed/saving/saved?
1593+ input . style = style . checkboxInputStyle
1594+ // colorCarrier.style = style.checkboxStyle
1595+ rhs . appendChild ( input )
15961596
15971597 function fix ( x ) {
15981598 if ( ! x ) return [ ] // no statements
@@ -1646,7 +1646,7 @@ export function buildCheckboxForm (dom, kb, lab, del, ins, form, dataDoc, trista
16461646 if ( ! editable ) return box
16471647
16481648 const boxHandler = function ( _e ) {
1649- tx . style = 'color: #bbb;' // grey -- not saved yet
1649+ colorCarrier . style . color = '#bbb;' // grey -- not saved yet
16501650 const toDelete = input . state === true ? ins : input . state === false ? del : [ ]
16511651 input . newState =
16521652 input . state === null
@@ -1678,7 +1678,8 @@ export function buildCheckboxForm (dom, kb, lab, del, ins, form, dataDoc, trista
16781678 debug . log ( ' @@@@@ weird if 409 - does hold statement' )
16791679 }
16801680 }
1681- tx . style = 'color: #black; background-color: #fee;'
1681+ colorCarrier . style . color = 'color: #black;'
1682+ colorCarrier . style . backgroundColor = '#fee;'
16821683 box . appendChild (
16831684 errorMessageBlock (
16841685 dom ,
@@ -1688,7 +1689,7 @@ export function buildCheckboxForm (dom, kb, lab, del, ins, form, dataDoc, trista
16881689 )
16891690 )
16901691 } else {
1691- tx . style = 'color: #black;'
1692+ colorCarrier . style = 'color: #black;'
16921693 input . state = input . newState
16931694 input . textContent = {
16941695 true : checkMarkCharacter ,
@@ -1710,7 +1711,7 @@ export function fieldLabel (dom, property, form) {
17101711 }
17111712 const anchor = dom . createElement ( 'a' )
17121713 if ( property . uri ) anchor . setAttribute ( 'href' , property . uri )
1713- anchor . setAttribute ( 'style' , 'color: #3B5998; text-decoration: none;' ) // Not too blue and no underline
1714+ anchor . setAttribute ( 'style' , style . fieldLabelStyle ) // Not too blue and no underline
17141715 anchor . textContent = lab
17151716 return anchor
17161717}
0 commit comments