-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d4e9108
commit ee2e4e1
Showing
3 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
ui-admin/src/forms/designer/split/FormElementFreetextEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Question, QuestionType } from '@juniper/ui-core' | ||
import React, { useState } from 'react' | ||
import { Textarea } from 'components/forms/Textarea' | ||
import { questionFromRawText } from '../../../util/juniperSurveyUtils' | ||
|
||
export const FormElementFreetextEditor = ({ question, onChange }: { | ||
question: Question, onChange: (newQuestion: Question) => void | ||
}) => { | ||
const [freetext, setFreetext] = useState<string>('') | ||
|
||
return <Textarea | ||
className="form-control mb-3 p-2" | ||
value={freetext} | ||
rows={15} | ||
onChange={value => { | ||
setFreetext(value) | ||
const newQuestionObj = questionFromRawText(value) | ||
const newType = newQuestionObj.type as QuestionType | ||
//questionFromRawText can only reasonably predict the type of question, it's choices, and it's text. | ||
//We'll pick those three fields out and allow the user to decide the rest of the fields explicitly. | ||
onChange({ | ||
...question, | ||
type: newType, | ||
title: newQuestionObj.title || '', | ||
choices: newQuestionObj.choices | ||
} as Question) | ||
}} | ||
label={'Freetext'} | ||
labelClassname={'mb-0'} | ||
infoContent={`Paste in question text to automatically generate a survey question. For text questions, | ||
simply paste in the text. For radio and dropdown questions, paste the question text followed by | ||
a new option on each line.`} | ||
/> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters