One Custom Rendering for Multiple Form Elements

Is it possible to create one custom renderer and map it to Multiple Form elements in JSON forms ?

For Example, Lets say I have two text box and I want to render this two text box in to star rating custom render and I want to create only 1 custom renderer for this two fields so that I don’t have to duplicate code. Is this possible ?

Hi @vijaysince89,

Yes that’s easily possible. The renderers are determined via a “tester” system. A tester is really not much more than a function with the signatur (uischema, schema) => number and the one with the highest number wins. Therefore you can implement the tester in any way you want and let your custom renderer “win” for as many controls as you like. Of course the code of your renderer then needs to be generic enough to also handle all cases it’s called on.

1 Like

So, if I want to render the 100 textboxes, do I need to write the code(tester) for each one?

Hi @ababeel-ceo,

Testers can be very generic. For example the default tester for text simply looks at the type in the JSON Schema and will be applied for all type: 'string' elements. So there is no need to write a tester for each property.