bem / bem-components

Set of components for sites development
https://bem.info/libraries/classic/bem-components/6.0.0/
Other
333 stars 87 forks source link

input: add pattern attr #962

Closed voischev closed 9 years ago

voischev commented 10 years ago

Для валидации форм решили попробовать возможности hmtl5, но блок их не поддерживает http://www.the-art-of-web.com/html/html5-form-validation/

veged commented 10 years ago

could you make PR? it doesn't looks hard

veged commented 10 years ago

see https://github.com/bem/bem-components/pull/963/files

narqo commented 10 years ago

@veged don't you think, that it would be weird to have a public attribute, that wouldn't work across all of supported browsers? For me it's like to have "position" field in popup, that would work only in Chrome.

I don't believe in this kind of API. This kind of "assumptions" should be implemented on the project level.

@voischev may be you could add something like the code below to your project:

block('input')(
  def()(function() {
    applyNext({ _ctx : this.ctx });
  }),
  elem('control').attrs()(function() {
    var attrs = applyNext();
    attrs.pattern = this._ctx.attrs.pattern;
    return attrs;
  })
)
veged commented 10 years ago

@narqo ouch, miss that cross browser nuance :-/ +1 for yours project-level variant

veged commented 10 years ago

but from another point of view — what gonna be wrong if we add pattern attr for browsers where it doesn't supported? seems like they will be ignore it, so we have auto fallback ;-)

narqo commented 10 years ago

So we would have a part of API, which we doesn't control. How would we document it (and guarantee it) for our internal "enterprise" users?

dfilatov commented 10 years ago

+1 to @narqo We should guarantee functionality of every supported attribute.

voischev commented 10 years ago

:+1: I think I need to support inline method of writing attrs. Now this is not possible, without appending libs components

html provides such an opportunity

veged commented 10 years ago

@voischev Yeah, you are right!

But I can't imagine good API for that. Right now __control element creates internally and doesn't have representation in BEMJSON. However some attributes for __control taken from input object.

If we add some field like controlAttrs it will be ugly (especially with another control attrs which sets from root of object). We also can say that input field attrs stay for __control attributes and lost possibility to set attributes for block node itself.

Any other variants?

aristov commented 10 years ago

302

veged commented 9 years ago

close in favour of possibility to redefine it on own level (see #1053)