Replacement for disable-validation-message in Angular2

I’m not sure disable-validation-message does what I want but I found it to be close enough.

Basically I’m looking for a way to prevent angular from setting errors on a Control input defined by formBuilder and use maxlength as well.

<input type="text" ngControl="foo" maxlength="500" />

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Update

const DUMMY_MAX_LENGTH_VALIDATOR = CONST_EXPR(
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => DummyMaxLengthValidatorr), multi: true}));

@Directive({
  selector: '[maxlength][ngControl],[maxlength][ngFormControl],[maxlength][ngModel]',
})
export class DummyMaxLengthValidator {
  validate(control) {}
}

than at your component add

@Component({
  ...
  providers: [DUMMY_MAX_LENGTH_VALIDATOR]
})

original

This might work but is likely to break eventually

<input type="text" ngControl="foo" [attr.maxlength]="'500'" />

AFAIK currently maxlength is read by constructor(@Attribute('maxlength') ...) which only passes static values. Making it a bound value might be able to work around. Besides that, the validators are applied for the [ngControl][maxlength] selector.