lektor / lektor

The lektor static file content management system

Home Page:https://www.getlektor.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Field Type ignores `addon_label`

relikd opened this issue · comments

Consider the example below, I would expect the label to show the text "hi" but instead Lektor only prints "0".
If I replace the type "test" with "integer" it works as expected.

Model:

[fields.why]
type = test
addon_label = hi

Python custom lektor.types.base.Type:

class TestType(Type):
    widget = 'integer'

    def value_from_raw(self, raw: 'RawValue') -> int:
        return int(raw.value or '0')

[...]
self.env.add_type(TestType)

It looks like the parsing of the addon_label option (in order to pass it on to the Admin frontend) happens in SingleInputType.to_json.

I suspect that if you changed your custom type (TestType) to inherit from lektor.types.primitives.SingleInputType instead of lektor.types.base.Type, your addon_label would work as expected.

Indeed it does.

Is that something that should be fixed in code or mentioned in the documentation?

I think it's probably a documentation issue.

It appears that only some of the Admin UI widget types support addon_labels.

In particular, only the singleline-text, integer, float, datepicker, slug, and url widgets support addon_text. The built-in types that use these widgets all inherit from SingleInputType.
(The flow, multiline-text, select, checkboxes, and checkbox widgets do not support addon_text.)

I suppose we could add a rubric about this in the Adding New Field Types section of the documentation.

And also here https://www.getlektor.com/docs/api/db/type/, where the "wrong" type is used.

I've just opened lektor/lektor-website#357 to track this.

Closing this ticket...