numberField.tsx 648 B

1234567891011121314151617181920212223242526272829303132
  1. import InputField from 'sentry/components/deprecatedforms/inputField';
  2. type Props = {
  3. max?: number;
  4. min?: number;
  5. } & InputField['props'];
  6. export default class NumberField extends InputField<Props> {
  7. coerceValue(value) {
  8. const intValue = parseInt(value, 10);
  9. // return previous value if new value is NaN, otherwise, will get recursive error
  10. const isNewCoercedNaN = isNaN(intValue);
  11. if (!isNewCoercedNaN) {
  12. return intValue;
  13. }
  14. return '';
  15. }
  16. getType() {
  17. return 'number';
  18. }
  19. getAttributes() {
  20. return {
  21. min: this.props.min || undefined,
  22. max: this.props.max || undefined,
  23. };
  24. }
  25. }