-
Notifications
You must be signed in to change notification settings - Fork 18
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
form submit with validate by default #207
Comments
in form.browser.js _onSubmit: function(e, data) {
e.preventDefault();
this._emit('submit', this.getVal());
this.validate().then(fieldsStatuses => {
if (this.checkFields(fieldsStatuses)) {
this._emit('success', this.getVal());
} else {
this.getInvalidFields().then(invalidFields => {
this._emit('error', this.getVal());
invalidFields[0].getControl().setMod('focused');
});
}
});
} in user block: modules.define('form-contacts',
['i-bem-dom', 'form', 'store-auth'],
function(provide, bemDom, Form, auth) {
provide(bemDom.declBlock(this.name, /** @lends app.prototype */{
onSetMod: {
js: {
inited: function() {
this._form = this.findChildBlock(Form);
this._form._events().on('success', this._onFormSuccess, this);
}
}
},
_onFormSuccess: function(e, data) {
console.log(data);
}
}));
}); or /**
* @module app
*/
modules.define('form-login',
['i-bem-dom', 'form', 'jquery', 'store-auth'],
function(provide, bemDom, Form, $, auth) {
provide(bemDom.declBlock(this.name, /** @lends app.prototype */{
onSetMod: {
js: {
inited: function() {
this._form = this.findChildBlock(Form);
this._form._events().on('success', (e, data) => auth.login(data));
}
}
}
}));
}); Very simple in use 👍 |
belozer
changed the title
form submit and validate by default
form submit with validate by default
Aug 18, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now:
With validate by default:
or add new event
success
, ordata
The text was updated successfully, but these errors were encountered: