Closed bsh-generator closed 2 months ago
three functions are added to Validator
to simplify the access to items status:
validator.validateItem('filed-name') // replacing : validator.items?.email?.validate()
validator.itemMessage('filed-name') // replacing : validator.items?.email?.message
validator.isItemValid('filed-name') // replacing : validator.items?.email?.valid
Feature Request
Summary:
The current method of accessing validation statuses and messages involves deep property access (e.g.,
validator.items.<item>.<message|valid|validate>
). To enhance usability and improve code readability, a simpler and more intuitive way to access validation results should be provided.Use Case:
In many scenarios, developers need to quickly and easily check the validation status of various fields or elements. The existing method, which requires navigating through multiple properties (
validator.items.<item>.<message|valid|validate>
), can be cumbersome, especially when dealing with complex forms or data structures.A simplified API for accessing validation status and messages would streamline development, reduce errors, and improve overall developer experience.
Expected Behavior:
Simplified Access:
validator.items.username.valid
, allow access through a simpler syntax likevalidator.getStatus('username').valid
.Flexible Retrieval:
validator.getStatuses(['username', 'email'])
could return an object with validation statuses for both fields.Consistent and Intuitive API:
Backward Compatibility:
Possible Implementation:
getStatus(fieldName)
orgetStatuses(fieldNamesArray)
, that returns the validation status and message in a simplified format.Example: