Skip to content
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/date picker value entering #6478

Merged
16 changes: 13 additions & 3 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const Calendar = React.memo(
};

const onInputBlur = (event) => {
!props.keepInvalid && updateInputfield(props.value);
updateInputfield(props.value, true);
props.onBlur && props.onBlur(event);
setFocusedState(false);
};
Expand Down Expand Up @@ -144,9 +144,10 @@ export const Calendar = React.memo(

const updateValueOnInput = (event, rawValue, invalidCallback) => {
try {
const value = parseValueFromString(rawValue);
const value = parseValueFromString(props.timeOnly ? rawValue.replace('_','') : rawValue);
melloware marked this conversation as resolved.
Show resolved Hide resolved

if (isValidSelection(value)) {
console.log('valid')
updateModel(event, value);
updateViewDate(event, value.length ? value[0] : value);
}
Expand Down Expand Up @@ -1778,6 +1779,8 @@ export const Calendar = React.memo(

const updateModel = (event, value) => {
if (props.onChange) {
const originInputValue = event.target.value;

const newValue = cloneDate(value);

viewStateChanged.current = true;
Expand All @@ -1797,6 +1800,8 @@ export const Calendar = React.memo(
value: newValue
}
});

event.target.value = originInputValue;
}
};

Expand Down Expand Up @@ -2418,7 +2423,7 @@ export const Calendar = React.memo(
return true;
};

const updateInputfield = (value) => {
const updateInputfield = (value, formatAlways) => {
if (!inputRef.current) {
return;
}
Expand Down Expand Up @@ -2457,6 +2462,11 @@ export const Calendar = React.memo(
}
}

if (inputRef.current.value.length === formattedValue.length - 1 && !formatAlways) {
melloware marked this conversation as resolved.
Show resolved Hide resolved
return;
}
console.log(inputRef.current.value, formattedValue)

inputRef.current.value = formattedValue;
};

Expand Down
Loading