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

Set up a computed field with an appropriate validator

Open ghost opened this issue 4 years ago • 5 comments

Hi!

I am using CKAN 2.9 and I would like to have a field that is not set up by the user in the form, but computed separately and then displayed.

I started to set form_snippet to null, but by doing this, the field is always reset to null each time I try to modify the dataset.

I have been advised to use the keep_old_value_if_missing validator. When a value for a given field on the form is missing (which is my case), the previously existing value is given.

This is a problem for me because, at the beginning, there is no previously existing value. The validator as it is now cannot work for me, unless I manage to give a random default value at the beginning.

How can I modify this validator so that it does what I want?

ghost avatar Mar 08 '21 15:03 ghost

what is the field computed from? You could add an output_validator to do the computation each time the dataset is accessed instead of saving it in the db.

wardi avatar Mar 08 '21 15:03 wardi

It is getting its value from an API. I don't understand how output_validators work.

maxclac avatar Mar 08 '21 15:03 maxclac

keep_old_value_if_missing seems like what you need then. Sounds like a small fix to make it work with initial missing values.

wardi avatar Mar 08 '21 16:03 wardi

It is maybe a small fix but I am a bit confused as to how to do it.

maxclac avatar Mar 08 '21 16:03 maxclac

This is more complicated than I imagined. I am going to leave this for a moment but it would be nice to have a validator for this use case in the future.

maxclac avatar Mar 09 '21 15:03 maxclac