bem-contrib / bem-forms

Forms building library on BEM methogology
33 stars 18 forks source link

External errors suggestion #140

Closed s-panferov closed 8 years ago

s-panferov commented 9 years ago

After working with this library for a while, I think that form-field needs a method to set external errors. It is very useful in cases with external validation (e.g. on the server side) or complex business logic validation when some external data or another fields are involved.

Example API:

formField.setErrors(errors: string[])
formField.clearErrors() // is a shortcut for formField.setErrors([])
awinogradov commented 9 years ago

For setup one error message you can use https://github.com/bem/bem-forms/blob/master/common.blocks/form-field/_message/form-field_message.browser.js#L37 Method setErrors must also be able to work with object because form-field can work with many validations types https://github.com/bem/bem-forms/blob/master/desktop.bundles/index/index.bemjson.js#L29

Ex:

formField.setErrors({
    required: String
});