nova-json-schema-field icon indicating copy to clipboard operation
nova-json-schema-field copied to clipboard

Set schema dinamically

Open fedeisas opened this issue 6 years ago • 5 comments

Hi there. Loving this package. Any ideas how can I implement this in a way that I can solve the schema on runtime?

Let's say you have User that belongs to Organization. The Organization has their required fields stored in them. So when editing a User you can say: the fields for this User belonging to some Organization are given by $this->schema($resource) or something like that.

fedeisas avatar Dec 10 '18 17:12 fedeisas

Hello. If i got it right:

  1. In user fields you just NovaJsonSchemaField::make('Settings', $this->schema())
  2. $this->schema() returns your user->organization->schema or empty array (in case of creation of a new User)

NikolaySav avatar Dec 10 '18 19:12 NikolaySav

Hey @NikolaySav! Thanks for replying.

This works only when showing the edit form. But when saving (POST), $this is not filled yet, so I can't have required fields.

fedeisas avatar Dec 11 '18 00:12 fedeisas

Can you share your code?

NikolaySav avatar Dec 11 '18 01:12 NikolaySav

When displaying the edit form, onfields(Request $request) method you can do if ($this->organization).

When submitting form, onfields(Request $request) method you can't do if ($this->organization) becase the resource is not filled with the model attributes.

fedeisas avatar Dec 11 '18 20:12 fedeisas

This would be really nice. I think it could be achieved by using merge on a belongsto field and this one - similar to the way the Place field interacts with other address fields.

Also it seems like the type inside schema is not used atm. Support for select would be nice too.

ppisecky avatar Dec 21 '18 14:12 ppisecky