feat: automatic next button label updation (#1848)

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
Dhruwang Jariwala
2024-01-03 19:41:06 +05:30
committed by GitHub
parent c62f041819
commit 60c7713aa0
@@ -99,6 +99,14 @@ export default function QuestionCard({
const open = activeQuestionId === question.id;
const [openAdvanced, setOpenAdvanced] = useState(question.logic && question.logic.length > 0);
const updateEmptyNextButtonLabels = (labelValue: string) => {
localSurvey.questions.forEach((q, index) => {
if (!q.buttonLabel || q.buttonLabel?.trim() === "") {
updateQuestion(index, { buttonLabel: labelValue });
}
});
};
return (
<Draggable draggableId={question.id} index={questionIdx}>
{(provided) => (
@@ -298,7 +306,7 @@ export default function QuestionCard({
question.type !== TSurveyQuestionType.CTA ? (
<div className="mt-4 flex space-x-2">
<div className="w-full">
<Label htmlFor="buttonLabel">Button Label</Label>
<Label htmlFor="buttonLabel">&quot;Next&quot; Button Label</Label>
<div className="mt-2">
<Input
id="buttonLabel"
@@ -307,9 +315,11 @@ export default function QuestionCard({
maxLength={48}
placeholder={lastQuestion ? "Finish" : "Next"}
onChange={(e) => {
if (e.target.value.trim() == "") e.target.value = "";
updateQuestion(questionIdx, { buttonLabel: e.target.value });
}}
onBlur={(e) => {
updateEmptyNextButtonLabels(e.target.value);
}}
/>
</div>
</div>