BaseMaterialNumberValueAccessor<T> constructor
BaseMaterialNumberValueAccessor<T> (
- MaterialInputComponent input,
- NgControl control,
- bool changeUpdate,
- bool keypressUpdate,
- bool blurFormat, [
- NumberFormat? _numberFormat,
Implementation
BaseMaterialNumberValueAccessor(
MaterialInputComponent input,
NgControl control,
bool changeUpdate,
bool keypressUpdate,
bool blurFormat,
[this._numberFormat])
: super(input, control) {
// The type values set via number directives are invalid values for the
// 'type' attribute on the underlying 'input' element, so set the value
// back to 'text' instead.
input.type = 'text';
assert(!(changeUpdate && keypressUpdate),
'Cannot update both on keypress and change.');
if (changeUpdate) {
_updateStream = input.onChange;
} else if (keypressUpdate) {
_updateStream = input.onKeypress;
} else {
_updateStream = input.onBlur;
}
if (blurFormat) {
disposer.addStreamSubscription(input.onBlur.listen((_) {
//if (input == null) return; // Input is no longer valid
final parsedNumber = parseNumber(input.inputText);
// If the value parses, it's a number so format it as such.
if (parsedNumber != null) {
super.writeValue(parsedNumber);
}
}));
}
}