jsonforms

json-forms custom renderer tester for multiple fields


I've created a custom renderer with its tester:

import { rankWith, scopeEndsWith } from '@jsonforms/core'

export default rankWith(
  3, //increase rank as needed
  scopeEndsWith('uiSchema')
)

and it works correctly; but I cannot figure out how to update this tester to match also other fields (not just the one whose scope ends with 'uiSchema', so let' say for example that I want this custom renderer to be used for fields with scope ending with 'uiSchema' AND 'uiDescription');


Solution

  • I've found inspecting the testers source code in jsonforms that it provides and and or functions to combine testers

    import { rankWith, scopeEndsWith, or } from '@jsonforms/core'
    
    export default rankWith(
      3, //increase rank as needed
      or(scopeEndsWith('name'), scopeEndsWith('description'))
    )
    

    Alternatively anyway the tester is just a function that receives 3 arguments, and you can write your own doing whatever you want inside; you just need to return a boolean telling jsonforms if the renderer has to be ranked or not:

    import { rankWith, scopeEndsWith, or } from '@jsonforms/core'
    
    export default rankWith(
      3, //increase rank as needed
      (uischema, schema, context) => {
        // avoid using the renderer if it's a layout
        if (uischema.type === 'Control') {
          // test whatever you want...
          return true
        }
        return false
      }
    )