ckanext-scheming icon indicating copy to clipboard operation
ckanext-scheming copied to clipboard

wip: Add validator for null form_snippets to prevent removing values.

Open boykoc opened this issue 4 years ago • 2 comments

When using ckanext-scheming you are able to add a field to your schema but have it hidden in the web form UI by using "form_snippet": null. However, when a user edits the package the value/key are removed from the package object.

This validator allows you to hide the form_snippet without losing the value of the field. This does not create a read only version as in this use-case, the desire is to just not lose the existing value for "hidden" form fields. A read only value may require its own validator to prevent editing if a value is provided. This validator allows editing of the value via an API call for instance.

I've suggested this for scheming as the hidden form aspect that it's tied to is here instead CKAN core.

This was more or less lifted from ckanext-canada.

Related PRs / Issues: PR #168 Issue #66 https://github.com/ckan/ckan/issues/1839#issuecomment-48755345

boykoc avatar May 07 '20 14:05 boykoc

this won't work for resource fields, group/org fields or fields that are part of the original package schema. I think this feature would be better implemented in ckan core package_update by adding the original dict to the context passed through to validators.

wardi avatar May 07 '20 14:05 wardi

Thanks for the feedback. True on not working for certain fields.

I'm going to leave here just until I get a working version for ckan core as suggested.

boykoc avatar May 07 '20 15:05 boykoc