angular - md-input maxlength not working -
even if add maxlength="250" can enter value in agular2-material md-input.
- is there anyway can disable input field entering text after 250 char.
- is there alternative maxlenth.
my form input :
<div class="form-group"> <md-input type="text" required placeholder="name" formcontrolname="name" #namecounthint maxlength="250" class="full-width" dividercolor="{{changeform.controls.name.valid ? 'primary': 'accent'}}"> <md-hint align="end">{{namecounthint.charactercount}} / 250</md-hint> </md-input> <agile-control-messages color="primary" [control]="teamform.controls.name"></agile-control-messages> </div>
any great.
i found simple demo on how have validation , maybe you.
component template:
<form [ngformmodel]="someformhandle" [(ngsubmit)="onsubmit()"> <input class="form-control" [ngformcontrol]="somenumber"> <button class="btn btn-primary" [disabled]="!someformhandle.valid"> submit </button> </form>
component:
@component({ selector: 'some-form', templateurl: './some-form.component.html', directives: [form_directives] }) export class someform implements oninit { someformhandle:controlgroup; somenumber:abstractcontrol; constructor(private formbuilder:formbuilder) { } divisiblebyten(control:control) { return parseint(control.value) % 10 == 0 ? null : { divisiblebyten: true } } onsubmit(){ //some submit logic } ngoninit():void { this.someformhandle = this.formbuilder.group({ 'somenumber': ['', validators.compose([validators.required, validators.maxlength(250), this.divisiblebyten])] }); this.somenumber = this.someformhandle.find('somenumber'); } }
Comments
Post a Comment