-
Notifications
You must be signed in to change notification settings - Fork 18
email validator and base message work #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,11 @@ FormField.decl({ block : this.name, modName : 'has-validation', modVal : true }, | |
| 'inited' : function() { | ||
| this.__base.apply(this, arguments); | ||
|
|
||
| !this.hasMod('message') && console.warn('Message modifier required for form-field_has-validation', this); | ||
| !this.hasMod('message') && | ||
| console.warn('Message modifier required for form-field_has-validation', this); | ||
|
|
||
| this.on('blur', function(e, data) { | ||
| this._dirty = this._dirty || (this.getVal() != this._initVal); | ||
| this.on('blur', function() { | ||
| this._dirty = this._dirty || (this.getVal() !== this._initVal); | ||
| this.toggleMod('dirty', true, this._dirty); | ||
| this._dirty && this.validate(); | ||
| }.bind(this)); | ||
|
|
@@ -70,6 +71,11 @@ FormField.decl({ block : this.name, modName : 'has-validation', modVal : true }, | |
| this.getControl().toggleMod('invalid', true, Boolean(this._status)); | ||
|
|
||
| this.getMessage().toggleMod('invalid', true, Boolean(this._status)); | ||
|
|
||
| if(this.hasMod('message')) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лишневатое условие, кажется. |
||
| this.setMessageVal(this._status); | ||
| this._status && this.hasMod('focused') && this.getMessage().show(); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
common.blocks/form-field/_has-validation/form-field_has-validation.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // FIXME: this spec don't work without https://github.com/narqo/bem-pr/pull/90 | ||
| modules.define('spec', ['spec__utils', 'sinon', 'input', 'message', 'form-field'], function(provide, utils, sinon) { | ||
|
|
||
| describe('form-field_has-validation', function() { | ||
|
|
||
| var block, bemjson; | ||
|
|
||
| beforeEach(function() { | ||
| bemjson = { | ||
| block : 'form-field', | ||
| mods : { | ||
| 'has-validation' : true | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(function() { | ||
| block && utils.destruct(block); | ||
| }); | ||
|
|
||
| it('should not throw without `type` mod', function() { | ||
| block = utils.buildBlock('form-field', bemjson); | ||
| block.getVal().should.equal(''); | ||
| }); | ||
|
|
||
| it('should call show message when changes status focused', function() { | ||
| bemjson.mods.type = 'input'; | ||
| bemjson.mods.message = 'text'; | ||
| bemjson.content = { | ||
| elem : 'control', | ||
| content : { | ||
| block : 'input', | ||
| val : 'XXX' | ||
| } | ||
| }; | ||
| block = utils.buildBlock('form-field', bemjson); | ||
|
|
||
| // should not show for valid block | ||
| block.getControl().elem('control').focus(); | ||
| var spy = sinon.spy(block.getMessage(), 'show'); | ||
| block._updateStatus(); | ||
| (!!spy.called).should.be.false; | ||
|
|
||
| // should show for invalid block | ||
| block._status = 'error'; | ||
| block._updateStatus(); | ||
| (!!spy.called).should.be.true; | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| provide(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
common.blocks/form-field/_message/form-field_message_popup.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // FIXME: this spec don't work without https://github.com/narqo/bem-pr/pull/90 | ||
| modules.define('spec', ['spec__utils', 'sinon', 'form-field', 'message', 'popup', 'input'], function(provide, utils, sinon) { | ||
|
|
||
| describe('form-field_message_popup', function() { | ||
|
|
||
| var block; | ||
|
|
||
| beforeEach(function() { | ||
| block = utils.buildBlock('form-field', { | ||
| block : 'form-field', | ||
| mods : { | ||
| type : 'input', | ||
| message : 'popup' | ||
| }, | ||
| content : { | ||
| block : 'input' | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(function() { | ||
| block && utils.destruct(block); | ||
| }); | ||
|
|
||
| it('should show message on focus', function() { | ||
| var spy = sinon.spy(block.getMessage(), 'show'); | ||
|
|
||
| // without invalid | ||
| block.setMod('focused'); | ||
| block.delMod('focused'); | ||
| (!!spy.called).should.be.false; | ||
|
|
||
| // with invalid | ||
| block.setMod('invalid'); | ||
| block.setMod('focused'); | ||
| block.delMod('focused'); | ||
| (!!spy.called).should.be.true; | ||
| }); | ||
|
|
||
| it('should set popup`s anchor to input', function() { | ||
| var anchor = block.getMessage()._popup._anchor; | ||
|
|
||
| block.hasMod('type').should.be.true; | ||
|
|
||
| setTimeout(function() { | ||
| (!!anchor).should.be.true; | ||
| anchor.attr('class').should.equal(block.getControl().domElem.attr('class')); | ||
| }, 20); | ||
| }); | ||
| }); | ||
|
|
||
| provide(); | ||
| }); |
6 changes: 6 additions & 0 deletions
6
common.blocks/form-field/_validate/form-field_validate_email.deps.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [{ | ||
| shouldDeps : [ | ||
| { mod : 'has-validation' }, | ||
| { block : 'validation', mods : { email : true } } | ||
| ] | ||
| }]; |
31 changes: 31 additions & 0 deletions
31
common.blocks/form-field/_validate/form-field_validate_email.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * @module form-field | ||
| */ | ||
| modules.define('form-field', | ||
| ['validation_email', 'objects'], | ||
| function(provide, validateEmail, objects, FormField) { | ||
|
|
||
| /** | ||
| * E-mail form-field validation | ||
|
|
||
| * @exports | ||
| * @class form-field | ||
| * @bem | ||
| */ | ||
| FormField.decl({ modName : 'validate', modVal : 'email' }, /** @lends form-field.prototype */{ | ||
|
|
||
| onSetMod : { | ||
| 'js' : { | ||
| 'inited' : function() { | ||
| this.__base.apply(this, arguments); | ||
|
|
||
| this.getValidator().push(validateEmail(this.params.email)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| }); | ||
|
|
||
| provide(FormField); | ||
|
|
||
| }); |
13 changes: 13 additions & 0 deletions
13
common.blocks/form-field/_validate/form-field_validate_email.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| modules.define('spec', ['form-field'], function(provide) { | ||
|
|
||
| describe('form-field_validate_email', function() { | ||
|
|
||
| it('should add validate_email', function() { | ||
|
|
||
| }); | ||
|
|
||
| }); | ||
|
|
||
| provide(); | ||
|
|
||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это можно унести в beforeSetMod