Skip to content

Commit

Permalink
Merge pull request #577 from Opetushallitus/OY-4900-aloituspaikan-pak…
Browse files Browse the repository at this point in the history
…otettu-arvo-pois

Oy 4900 aloituspaikan pakotettu arvo pois
  • Loading branch information
heidilm authored Sep 20, 2024
2 parents 7b4078a + 808de0b commit 7e24fc2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/main/app/src/components/NumberInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import _fp from 'lodash/fp';
import { identity, isNaN, isNil, isNumber, noop, toString } from 'lodash';

import { Input, InputProps } from '#/src/components/virkailija';
import { parseFloatComma } from '#/src/utils';
Expand All @@ -14,25 +14,25 @@ type NumberInputProps = {
} & InputProps;

const floatToCommaStr = (value?: number | null) =>
_fp.isNil(value) ? '' : _fp.toString(value).replace('.', ',');
isNil(value) ? '' : toString(value).replace('.', ',');

const NumberInput = ({
onBlur = _fp.noop,
min = 0,
onBlur = noop,
min,
max,
fallbackValue = null,
parseValue = _fp.identity,
parseValue = identity,
...props
}: NumberInputProps) => {
const usedOnBlur = e => {
const value: string = e?.target?.value;
const floatValue = parseValue(value);
if (_fp.isNaN(floatValue) || _fp.isNil(floatValue)) {
if (isNaN(floatValue) || isNil(floatValue)) {
e.target.value = fallbackValue;
} else {
if (_fp.isNumber(max) && floatValue > max) {
if (isNumber(max) && floatValue > max) {
e.target.value = max;
} else if (_fp.isNumber(min) && floatValue < min) {
} else if (isNumber(min) && floatValue < min) {
e.target.value = min;
} else {
e.target.value = floatToCommaStr(floatValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const HakeutumisTaiIlmoittautumistapaSection = ({
<Field
name={`${name}.aloituspaikat`}
component={FormFieldIntegerInput}
min={0}
fallbackValue={null}
label={t('toteutuslomake.aloituspaikat')}
type="number"
/>
Expand Down

0 comments on commit 7e24fc2

Please sign in to comment.