запрещено начинать диапазон с 0
This commit is contained in:
parent
b3537381b7
commit
62a9237925
@ -16,6 +16,9 @@ interface Props {
|
|||||||
openBranchingPage: boolean;
|
openBranchingPage: boolean;
|
||||||
setOpenBranchingPage: (a: boolean) => void;
|
setOpenBranchingPage: (a: boolean) => void;
|
||||||
}
|
}
|
||||||
|
function ReplaceToNotStartZero (x: number) {
|
||||||
|
return(Number(x.toString().replace(/^0+/, '') || '0'))
|
||||||
|
}
|
||||||
|
|
||||||
export default function SliderOptions({ question, openBranchingPage, setOpenBranchingPage }: Props) {
|
export default function SliderOptions({ question, openBranchingPage, setOpenBranchingPage }: Props) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -29,7 +32,7 @@ export default function SliderOptions({ question, openBranchingPage, setOpenBran
|
|||||||
setStartError("");
|
setStartError("");
|
||||||
|
|
||||||
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
||||||
question.content.start = value;
|
question.content.start = ReplaceToNotStartZero(value);
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
@ -37,9 +40,19 @@ export default function SliderOptions({ question, openBranchingPage, setOpenBran
|
|||||||
setStepError("");
|
setStepError("");
|
||||||
|
|
||||||
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
||||||
question.content.step = value;
|
question.content.step = ReplaceToNotStartZero(value);
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
const updateStepsDebounced = useDebouncedCallback((value: string) => {
|
||||||
|
console.log("value")
|
||||||
|
console.log(value)
|
||||||
|
console.log(value.toString())
|
||||||
|
console.log("ReplaceToNotStartZero(Number(value)) _____________________________________")
|
||||||
|
console.log(ReplaceToNotStartZero(Number(value)))
|
||||||
|
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
||||||
|
question.content.step = ReplaceToNotStartZero(Number(value));
|
||||||
|
});
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
const calculateValues = () => {
|
const calculateValues = () => {
|
||||||
const { step, start } = question.content;
|
const { step, start } = question.content;
|
||||||
@ -117,8 +130,9 @@ export default function SliderOptions({ question, openBranchingPage, setOpenBran
|
|||||||
value={question.content.range.split("—")[0]}
|
value={question.content.range.split("—")[0]}
|
||||||
onChange={({ target }) => {
|
onChange={({ target }) => {
|
||||||
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
||||||
question.content.range = `${target.value}—${question.content.range.split("—")[1]}`;
|
question.content.range = `${Number(target.value)}—${question.content.range.split("—")[1]}`;
|
||||||
});
|
});
|
||||||
|
// if (/^0\d+$/.test(target.value.toString())) updateStepsDebounced(target.value);
|
||||||
}}
|
}}
|
||||||
onBlur={calculateValues}
|
onBlur={calculateValues}
|
||||||
/>
|
/>
|
||||||
@ -131,8 +145,9 @@ export default function SliderOptions({ question, openBranchingPage, setOpenBran
|
|||||||
value={question.content.range.split("—")[1]}
|
value={question.content.range.split("—")[1]}
|
||||||
onChange={({ target }) => {
|
onChange={({ target }) => {
|
||||||
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
updateQuestion<QuizQuestionNumber>(question.id, (question) => {
|
||||||
question.content.range = `${question.content.range.split("—")[0]}—${target.value}`;
|
question.content.range = `${question.content.range.split("—")[0]}—${Number(target.value)}`;
|
||||||
});
|
});
|
||||||
|
// if (/^0\d+$/.test(target.value.toString())) updateStepsDebounced(target.value);
|
||||||
}}
|
}}
|
||||||
onBlur={calculateValues}
|
onBlur={calculateValues}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user