implemented updating of option names. next: update option description

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-23 14:58:47 +01:00
parent 0eab5619d1
commit e5ab655787
6 changed files with 96 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
<script>
<script>
import { activeField } from './field_sync.svelte.js';
import { t } from '../translations.svelte.js';

View File

@@ -5,7 +5,7 @@
import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import { api, get, post } from '../../urls.svelte';
import { api, get, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import { user } from '../../user.svelte.js';
@@ -23,18 +23,28 @@
} else error(res);
}
async function patchOption(option, field, newVal){
let url = api(`poll/${id}/option/${option.id}`);
let data = {}
data[field] = newVal;
let res = await patch(url,data);
if (res.ok) {
yikes();
const json = await res.json();
} else error(res);
}
async function save_new_option(){
let url = api('poll/'+id+'/option');
let res = await post(url,new_option);
if (res.ok){
yikes();
const json = await res.json();
console.log(json);
poll.options = json.options;
} else error(res);
}
onMount(load);
</script>
@@ -63,7 +73,7 @@
{#each poll.options as option}
<tr>
<td>
<input type="text" value={option.name} />
<LineEditor editable={true} value={option.name} onSet={name => patchOption(option,'name',name)} />
</td>
<td>
<MarkdownEditor bind:value={option.description} />