senaite / senaite.core

Enterprise Open Source Laboratory System (LIMS)
https://senaite.com
GNU General Public License v2.0
254 stars 145 forks source link

Widget text extensions #2588

Closed ramonski closed 3 months ago

ramonski commented 3 months ago

Description of the issue/feature this PR addresses

This PR adds the ability to prepend/append text to common widgets in view/edit modes.

Additional text can be added by using directives.widget:

class IDepartmentSchema(model.Schema):
    """Schema interface
    """

    directives.widget("title",
                      before_text=">",
                      before_css_class="text-secondary",
                      after_text="<i class='fas fa-building'></i>",
                      after_css_class="text-primary",
                      wrapper_css_class="float-left mr-4")
    title = schema.TextLine(
        title=_(
            u"title_department_title",
            default=u"Name"
        ),
        description=_(
            u"description_department_title",
            default=u"Name of the department"
        ),
        required=True,
    )

    # Department ID
    directives.widget("department_id",
                      before_text_input="ID",
                      before_css_input="text-secondary",
                      widget_css_display="text-primary text-monospace",
                      widget_css_input="text-primary text-monospace",
                      after_text_input="<i class='fas fa-id-card'></i>",
                      after_css_input="text-primary")
    department_id = schema.TextLine(
        title=_(
            u"title_department_id",
            default=u"Department ID"
        ),
        description=_(
            u"description_department_id",
            default=u"Please provide a unique department identifier"
        ),
        required=True,
    )

Current behavior before PR

Only plain widget rendering possible

Desired behavior after PR is merged

Widgets can render with additional text before and after.

-- I confirm I have tested this PR thoroughly and coded it according to PEP8 and Plone's Python styleguide standards.