-
Notifications
You must be signed in to change notification settings - Fork 594
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
fix: validation not respecting step attribute in fast-number-field #6617
Comments
Yes, I agree. @tomokusaba any ideas? |
I know something is wrong with Validate. |
number-field.ts public validate(): void {
try {
parseFloat(this.value);
} catch (e) {
super.setValidity(
this.proxy.validity,
this.proxy.validationMessage,
this.control
);
return;
}
const parsedValue = parseFloat(this.valueAsNumber.toString());
const validValue = isNaN(parsedValue) ? null : parsedValue;
if (validValue !== null) {
const step = this.step || 1;
const max = this.max !== undefined ? this.max : Number.MAX_VALUE;
const min = this.min !== undefined ? this.min : -Number.MAX_VALUE;
const modulo = (validValue - min) % step;
if (modulo !== 0) {
validValue - modulo + (modulo < step / 2 ? 0 : step);
}
if (validValue > max) {
super.setValidity(
this.proxy.validity,
this.proxy.validationMessage,
this.control
);
}
if (validValue < min) {
super.setValidity(
this.proxy.validity,
this.proxy.validationMessage,
this.control
);
}
}
} |
I think we need an explicit version here - the fast-components package has been deprecated for a bit and the latest alpha has fixes for validation. I’d like to be able to pinpoint this and validate. Thanks! |
Closing due to deprecation of |
🐛 Bug Report
When using
fast-number-field
, the validation mechanism always assumes astep
value of1
regardless of the specifiedstep
value. This makes it impossible to use the field for decimal inputs in a form without disabling validation altogether.💻 Repro or Code Sample
🤔 Expected Behavior
Entering the value
1.05
should not produce any validation error.😯 Current Behavior
Entering the value
1.05
sets the control state to invalid resulting in the text "Value is invalid" displaying. The CSS included in the sample displays this text only when the:invalid
pseudo-selector applies to the control.💁 Possible Solution
It appears that a
proxy
element is used for validation purposes here. However, none of the validation-affecting attributes such asstep
are passed to the element.A mechanism to pass these attributes through to the proxy element, or possibly just using the actual created input as the proxy rather than a separate input element, could ensure that these attributes are respected.
🔦 Context
I'm trying to create a form that takes in a price. This needs to be a value containing up to 2 decimal places. However, currently, it's not possible to accept a price that is not an integer.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: