question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation Renderer has no way to provide success styling

See original GitHub issue

I’m submitting a feature request

Current behavior: I am able to create a custom validation renderer that detects when an element has become invalid. With this we can apply error styling and then we can detect when that element is transitioning from an invalid state, back to a valid state and I can then apply success styling. As seen here:

    render(instruction: RenderInstruction) {
       for (let {error, elements} of instruction.unrender) {
            for (let element of elements) {
                this.remove(element, error);
            }
        }

        for (let {error, elements} of instruction.render) {
            for (let element of elements) {
                this.add(element, error);
            }
        }
    }

    private add(element: Element, error: ValidationError) {
        // Add error styling
    }

    private remove(element: Element, error: ValidationError) {
        // Remove error styling
        // Add success styling
    }

But how would I apply success styling when the element was never invalid? I can see in my custom renderer that the render function is called, but the RenderInstruction of kind “validate” contains no elements for me to add styling to. On a new form, on a valid field, the RenderInstruction provided to the render method on my custom renderer looks like this:

kind: "validate"
render: Array[0]
unrender:Array[0]

As you can see, I have no way of knowing which elements were validated successfully therefore cannot apply styling.

Perhaps adding an unrender() event on the ValidationRenderer or a new kind on RenderInstruction could work?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
EisenbergEffectcommented, Oct 14, 2016

I would support the change. It’s a more flexible design and similar to what I’ve seen done in other libraries.

1reaction
jsobellcommented, Oct 14, 2016

OK, quick brain dump because it’s 11:30pm here and my synapses are shutting down…

I have no issue making the change you suggest, as it should work around most of these problems, and this is one aspect I was wurbling on about when I mentioned needing more information in the renderer, but I think is also related to the discussion about having custom rules associated or ‘bound’ to arbitrary visual elements. This is one of those tricky crossovers between object and UI validation. Because we can have object level rules, but the user wants the results reflected on-screen, what binds the object level rule to anything in the DOM? As far as validation feedback is concerned we don’t care if the rule is linked to an input field or a span, as long as we can display the error. If we implement the solution where the user is handed a list of both property validation result and the related DOM entity, we really need to provide the DOM elements that they consider related even if they were not validation-bound inputs.

A simple example might be that firstname+lastname are less than 50 characters. We add this as a model rule, but it’s not linked to one input field, so the user wants the error displayed below those two fields. When the renderer is called, it has no visual element associated, so how does the user associate this with a point in the DOM to display the error or the green ‘OK’ result discussed by the OP?

My original suggestion was that all Model level rules have a fake property or ‘ID’, so we could have a custom attribute anywhere on the form to flag the location (or locations) to be passed to the renderer, and in the above example it would probably be on a div enclosing first and last name input fields.

Essentially, once we start raising events intended for UI feedback (even though they are really only property feedback) we need to allow this to happen, as moving the error-centric to be rule-centric needs to be able to provide enough details to allow ui-centric coding when required.

Treacherous partly gets around this by always having the entire collection of passed and failed rules available (as your solution would do), and you can request the message and status of any property by name, even if that property is an object level pseudo-property/ID/tag.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation
The ValidationController orchestrates the UI process of validating properties in response to various triggers and surfacing validation errors via renderers.
Read more >
How to Create Renderers for Custom Expectations ...
First, decide which renderer types you need to implement. Use the following annotated Validation Result as a guide (most major renderer types represented):....
Read more >
How to properly validate input values with React.JS?
First, here is an example of what I'll mention below: http://jsbin.com/rixido/2/edit. How to properly validate input values with React.JS? However you want.
Read more >
How to Validate Forms with Bootstrap 5
These validation styles are used to showcase some form styles and messages, both errors and success states for form fields, and can be...
Read more >
Forms and Validation - Apache Tapestry
Tapestry provides support for creating and rendering forms, populating their ... If there have been no validation errors, then a "success" event is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found