oruga icon indicating copy to clipboard operation
oruga copied to clipboard

Support custom constraint validation (setCustomValidity)

Open blm768 opened this issue 1 year ago • 1 comments

Currently, Oruga provides mechanisms to enable HTML constraint validation, and it even provides a way to override the browser's validation message when the input is invalid (via the validationMessage prop). However, this validation message only appears if the element fails a native constraint validation check, and it only applies to the messages that Oruga shows; the element's own constraint validation state is unaffected.

It would be convenient to have an officially supported way to call setCustomValidity on Oruga's form control elements. This might either replace or supplement the current validationMessage prop. Just passing a string would likely be sufficient, although I've run into race conditions when trying to update a string prop right before submitting a form, so for that use case, we might need some mechanism to either make the call to setCustomValidity happen faster (e.g. by passing a validation function and attaching a flush: "sync" watcher) or provide an event for which we can wait so we know that constraint validation is in the expected state.

We'd probably also need to hook into the logic that propagates validation messages up to the parent field; any changes in the validation message probably should trigger a call to checkHtml5Validity (perhaps excepting cases where the field is currently focused and was previously valid, as it's less annoying to wait for the user to complete their input before displaying a message).

blm768 avatar May 17 '24 03:05 blm768

[We] might need some mechanism to either make the call to setCustomValidity happen faster (e.g. by passing a validation function and attaching a flush: "sync" watcher) or provide an event for which we can wait so we know that constraint validation is in the expected state.

I suppose this isn't a terrible use case for nextTick.

blm768 avatar May 17 '24 16:05 blm768

@blm768 Could you make a showcase PR with some prototype changes to make it kinda more understandable what you want? It doesn't have to be a fully mergeable PR. I can do the details later, but I need some more understanding of the problem.

mlmoravek avatar Jul 12 '24 10:07 mlmoravek

It might be a bit before I get the bandwidth to put together a PR, but writing something has been on my to-do list for a while. I'll push it up the list a bit.

blm768 avatar Jul 12 '24 17:07 blm768