Skip to content

Handle custom invalid message when validating forms #207

@sartaj10

Description

@sartaj10

Currently, I have this

        "slip": {
            "type": "string",
            "title": "Slip",
            'pattern': '^P(?:\\d+(?:\\.\\d+)?W)?(?:\\d+(?:\\.\\d+)?D)?(?:T(?:\\d+(?:\\.\\d+)?H)?(?:\\d+(?:\\.\\d+)?M)?(?:\\d+(?:\\.\\d+)?S)?)?$',
            "description": "ISO 8601 Duration that allows the start of each run to be as much as the Duration later than their ideal scheduled time. Default is 5 minutes (PT5M)",
            "default": "PT5M",
        },

If i want to add a key such as x-invalid-message: "'%s' is not a valid ISO 8601 duration.", the frontend ignores the validation entirely. It's probably because AJV rejects any unknown keywords in strict mode, breaking all validation.

Perhaps, we'll have to update json-forms-esm and do something like

import { createAjv } from "@jsonforms/core";

const handleDefaultsAjv = createAjv({ useDefaults: true });
handleDefaultsAjv.addKeyword({ keyword: "x-invalid-message" });

Doing this, would then allow us to show better invalid messages to the user.

Currently, in the above case, the UI shows

Image

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions