New list response
This commit is contained in:
parent
2e4f0eaf30
commit
24f0e82571
2
db.go
2
db.go
@ -99,7 +99,7 @@ CREATE TABLE IF NOT EXISTS survey_quests(
|
|||||||
title VARCHAR(255),
|
title VARCHAR(255),
|
||||||
description TEXT,
|
description TEXT,
|
||||||
placeholder VARCHAR(255),
|
placeholder VARCHAR(255),
|
||||||
kind ENUM('text', 'int', 'ucq', 'mcq') NOT NULL,
|
kind ENUM('text', 'int', 'ucq', 'mcq', 'list', 'list1', 'list2', 'list3', 'list4', 'list5', 'list6', 'list7', 'list8', 'list9') NOT NULL,
|
||||||
FOREIGN KEY(id_survey) REFERENCES surveys(id_survey)
|
FOREIGN KEY(id_survey) REFERENCES surveys(id_survey)
|
||||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
|
43
ui/src/components/ListInput.svelte
Normal file
43
ui/src/components/ListInput.svelte
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<script>
|
||||||
|
import { createEventDispatcher, tick } from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let className = '';
|
||||||
|
export { className as class };
|
||||||
|
|
||||||
|
export let qid = "";
|
||||||
|
export let kind = "list";
|
||||||
|
export let value = "";
|
||||||
|
export let placeholder = "";
|
||||||
|
|
||||||
|
let nb;
|
||||||
|
let mval = [];
|
||||||
|
$: mval = value?value.split('\n'):[];
|
||||||
|
$: {
|
||||||
|
nb = Number(kind.substring(4));
|
||||||
|
while (mval.length < nb) {
|
||||||
|
mval.push("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each mval as v, i}
|
||||||
|
<input
|
||||||
|
id={qid + "l" + i}
|
||||||
|
class={className}
|
||||||
|
type="text"
|
||||||
|
bind:value={mval[i]}
|
||||||
|
{placeholder}
|
||||||
|
on:change={() => { value = mval.join('\n').trim(); dispatch("change"); }}
|
||||||
|
on:blur={() => { if (kind == "list" && i == mval.length - 1 && mval[i] == "") { mval.pop(); mval = mval; } }}
|
||||||
|
>
|
||||||
|
{/each}
|
||||||
|
{#if kind == "list" && (mval.length == 0 || mval[mval.length-1] != "")}
|
||||||
|
<input
|
||||||
|
class={className}
|
||||||
|
type="text"
|
||||||
|
{placeholder}
|
||||||
|
on:focus={() => { mval.push(""); mval = mval; tick().then(() => document.getElementById(qid + "l" + (mval.length-1)).focus()); }}
|
||||||
|
>
|
||||||
|
{/if}
|
@ -1,6 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
import ListInput from './ListInput.svelte';
|
||||||
import QuestionHeader from './QuestionHeader.svelte';
|
import QuestionHeader from './QuestionHeader.svelte';
|
||||||
import QuestionProposals from './QuestionProposals.svelte';
|
import QuestionProposals from './QuestionProposals.svelte';
|
||||||
import ResponseCorrected from './ResponseCorrected.svelte';
|
import ResponseCorrected from './ResponseCorrected.svelte';
|
||||||
@ -69,7 +70,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if edit}
|
{#if edit}
|
||||||
{#if question.kind == 'text' || question.kind == 'int'}
|
{#if question.kind && (question.kind == 'text' || question.kind == 'int' || question.kind.startsWith('list'))}
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-2 col-form-label" for="q{qid}placeholder">Placeholder</label>
|
<label class="col-2 col-form-label" for="q{qid}placeholder">Placeholder</label>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@ -127,6 +128,14 @@
|
|||||||
placeholder={question.placeholder}
|
placeholder={question.placeholder}
|
||||||
on:change={() => { dispatch("change"); }}
|
on:change={() => { dispatch("change"); }}
|
||||||
>
|
>
|
||||||
|
{:else if question.kind && question.kind.startsWith('list')}
|
||||||
|
<ListInput
|
||||||
|
class="ml-5 col-sm-2 form-control my-1"
|
||||||
|
kind={question.kind}
|
||||||
|
bind:value={value}
|
||||||
|
placeholder={question.placeholder}
|
||||||
|
on:change={() => { dispatch("change"); }}
|
||||||
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<textarea
|
<textarea
|
||||||
class="form-control"
|
class="form-control"
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<select class="form-select" id="q{qid}kind" bind:value={question.kind}>
|
<select class="form-select" id="q{qid}kind" bind:value={question.kind}>
|
||||||
<option value="text">Texte</option>
|
<option value="text">Texte</option>
|
||||||
|
<option value="list">Liste de champs de texte</option>
|
||||||
|
<option value="list5">Liste de champs de texte (5 champs)</option>
|
||||||
<option value="int">Entier</option>
|
<option value="int">Entier</option>
|
||||||
<option value="ucq">QCU</option>
|
<option value="ucq">QCU</option>
|
||||||
<option value="mcq">QCM</option>
|
<option value="mcq">QCM</option>
|
||||||
|
Reference in New Issue
Block a user