bem-contrib / bem-forms

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

Validation block and API #27

Closed qfox closed 9 years ago

qfox commented 9 years ago

We using it as a mix for input (or similar) blocks right now:

{
  block : 'input',
  mods : { theme : 'islands' },
  mix : [
    { block : 'form', elem : 'control' },
    { block : 'validation', mods : { numbers : true }, js : {/* validation params */} }
  ]
}

There is a lot of data that we should pass for each field and I really want to simplify it if possible.

Any guesses will help a lot.

The one that placed on the top of my mind probably have troubles with theme deps:

{
  elem : 'control',
  mods : { type : 'text', theme : 'islands', size : 'l', validation : 'numbers' },
  js : { validation : { /* validation params */ } }
}

control_validation_numbers will require validation_numbers block, form__control_type_text will require input and input_type_text, and form__control_theme_islands will require input_theme_islands. Right? Also it can internally regenerate the rest of needed bemjson by BH/BEMHTML but I'm afraid of missing deps here and need review.

I think that's all validation block needed to return some validation result. All other work with form should be placed in form_validation.

awinogradov commented 9 years ago

I don't see problems in current variant. You can build assets with all need deps on client. In this two variants you should do this. Why you want control now?)

qfox commented 9 years ago

@verybigman To have a light form variant ;-)

awinogradov commented 9 years ago

This resolve #5

qfox commented 9 years ago

And #14

qfox commented 9 years ago
module.require(['validate', 'validate_numbers'], function(Validate, numbers) {
  // ...
  var validate = new Validate();
  validate.push(numbers(‘Что-то не так’));
  validate.push(function (val) {
    return false;
  }, ['Ошибка 1', 'Ошибка 2']);
  // ...
  field.checkValidate =
    if (validate.run()) { // есть ошибки
      this.setMessage(validate.getErrors().join('')); // выводим массив с ошибками
    }
awinogradov commented 9 years ago

Solved