maxfordham / ipyautoui

create ipywidgets user input form pydantic model or jsonschema
https://maxfordham.github.io/ipyautoui/
42 stars 4 forks source link

✨ setting fieldProps on Vjsf #292

Closed tharwan closed 7 months ago

tharwan commented 7 months ago

Is your feature request related to a problem? Please describe. I am not entirely sure if this is a bug or a feature. Either way I am trying to customise Vjsf according to the docs. I experimented with setting fieldProps={"dense":True} or disableAll=True but none seems to have an effect.

And I could not find any example in the repo doing anything similar.

Describe the solution you'd like I would like to be able to set all properties of Vjsf.

Describe alternatives you've considered None

Additional context None

jgunstone commented 7 months ago

not sure what you mean exactly - it would be useful if you posted code to reproduce you example?

Vjsf is defined: https://github.com/maxfordham/ipyautoui/blob/7470e7d95e4dc4736f89bf9931a6f01ea187bb31/src/ipyautoui/autovjsf.py#L68-L73

so the editable attributes available to you are:

everything I've ever done is just uses the schema. at one point I ran the schema through this function: https://github.com/maxfordham/ipyautoui/blob/7470e7d95e4dc4736f89bf9931a6f01ea187bb31/src/ipyautoui/autovjsf.py#L41-L65 because you can't define names in python / pydantic like this: x-name.... but its not being used now so that could be part of the issue...?

the template file defaults to this: https://github.com/maxfordham/ipyautoui/blob/main/src/ipyautoui/vjsf.vue you could override the class in your notebook to apply a different template... I've never done this and don't know how it works... but I think probs that isn't required and you want to be able to pass config vars through the schema

maybe you can use the playground in the vjsf docs to try and reproduce what you're after... ?

tharwan commented 7 months ago

but I think probs that isn't required and you want to be able to pass config vars through the schema

Ah this did the trick!

I was assuming I could do:

Vjsf(schema=schema, fieldProps={"dense":True, "color":"purple"})

but unfortunately it just does nothing, no error either.

But doing:

schema = Model.schema()
schema["x-options"] = dict(fieldProps={"dense":True, "color":"purple"})
Vjsf(schema=schema, disableAll=True)

works just as expected. I will try to make a PR to add this do the readme.