MaterialPercentInputDirective constructor
MaterialPercentInputDirective(
- MaterialInputComponent input,
- HtmlElement element
Implementation
MaterialPercentInputDirective(
MaterialInputComponent input, HtmlElement element) {
// 'percent' is an invalid 'type' attribute value for the 'input' element.
// Use value 'text' instead.
input.type = 'text';
input.rightAlign = true;
element.dir = 'ltr';
final percentPattern = NumberFormat.percentPattern();
final percentLocation = percentPattern.symbols.PERCENT_PATTERN
.indexOf(percentPattern.symbols.PERCENT);
// If the percent symbol is closer to the end of the pattern make sure it is
// trailing.
if (percentLocation > percentPattern.symbols.PERCENT_PATTERN.length / 2) {
input.trailingText = percentPattern.symbols.PERCENT;
} else {
input.leadingText = percentPattern.symbols.PERCENT;
}
input.errorRenderer = _replaceErrorMessage;
}