-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat(validation): add error list to md-select #250
Conversation
Ullfis
commented
Sep 2, 2016
html <template>
<md-colors
md-primary-color="#627ebe"
md-accent-color="#62be7e">
</md-colors>
<require from="../node_modules/materialize-css/dist/css/materialize.css"></require>
<div class="container">
<div class="row">
<div class="col s12">
<md-input
md-label="First Name"
md-value.bind="firstName & validate:rules"
md-validate="true"
md-validate-success="good"
md-validate-error="aiai">
</md-input>
<md-input
md-label="Last Name"
md-placeholder="Last Name"
md-validate-success="good"
md-value.bind="lastName & validate:rules">
</md-input>
<md-input
md-type="email"
md-label="HTM5 email validation"
md-validate="true"
md-validate-success="good"
md-validate-error="Not a valid email"
md-value.bind="email">
</md-input>
<select md-select="label: My select label;" value.two-way="selectedValue & validate:rules">
<option value="" disabled selected>select an item</option>
<option value="item1">item 1</option>
<option value="item2">item 2</option>
<option value="item3">item 3</option>
<option value="item4">item 4</option>
</select>
</div>
</div>
<div style="margin-top: 15px;">
<button md-waves md-button click.delegate="validateModel()">validate</button>
</div>
<h5>${message}</h5>
<ul style="margin-top: 15px;" show.bind="controller.errors.length">
<li repeat.for="error of controller.errors">
<a href="#" click.delegate="error.target.focus()">
${error.message}
</a>
</li>
</ul>
</div>
</template> js import { inject, NewInstance } from 'aurelia-framework';
import { ValidationController, validateTrigger, ValidationRules } from 'aurelia-validation';
import { MaterializeFormValidationRenderer } from 'aurelia-materialize-bridge';
@inject(NewInstance.of(ValidationController))
export class App {
message = '';
firstName = '';
lastName = 'Doe';
email = '';
selectedValue = '';
controller = null;
rules = ValidationRules
.ensure('firstName').required().withMessage('First name is required')
.ensure('lastName')
.minLength(4)
.required()
.email()
.ensure('selectedValue')
.required()
.rules;
constructor(controller: ValidationController) {
this.controller = controller;
this.controller.addRenderer(new MaterializeFormValidationRenderer());
}
validateModel() {
this.controller.validate().then(v => {
if (v.length === 0) {
this.message = 'All is good!';
} else {
this.message = 'You have errors!';
}
});
}
} |
@MaximBalaganskiy and you seem to practice some kind of mind reading, right? 😏 |
Can't check at the moment, but I bet no. Like you said, original control On 2 Sep 2016 11:32 PM, "Daniel Bendel" notifications@github.com wrote:
|
issu.. mind reading is right. Label on select was an excellent addition! And since I already was into the validation stuff, my keyboard wouldn't stop typing. nope. no blur event attached to this. Maybe try sent an event from the input control. |
$(wrapper.children('input.select-dropdown')[0]).on('blur', this.handleBlur); something around there |