Optional form responses

This commit is contained in:
rxdn 2022-05-31 15:44:59 +01:00
parent 9722b82598
commit 4a121f6b63
7 changed files with 35 additions and 17 deletions

View File

@ -13,6 +13,7 @@ type inputCreateBody struct {
Style component.TextStyleTypes `json:"style"`
Label string `json:"label"`
Placeholder *string `json:"placeholder"`
Optional bool `json:"optional"`
}
func CreateInput(ctx *gin.Context) {
@ -69,7 +70,7 @@ func CreateInput(ctx *gin.Context) {
// 2^30 chance of collision
customId := utils.RandString(30)
formInputId, err := dbclient.Client.FormInput.Create(formId, customId, uint8(data.Style), data.Label, data.Placeholder)
formInputId, err := dbclient.Client.FormInput.Create(formId, customId, uint8(data.Style), data.Label, data.Placeholder, !data.Optional)
if err != nil {
ctx.JSON(500, utils.ErrorJson(err))
return
@ -82,6 +83,7 @@ func CreateInput(ctx *gin.Context) {
Style: uint8(data.Style),
Label: data.Label,
Placeholder: data.Placeholder,
Required: !data.Optional,
})
}

View File

@ -72,6 +72,7 @@ func UpdateInput(ctx *gin.Context) {
Style: uint8(data.Style),
Label: data.Label,
Placeholder: data.Placeholder,
Required: !data.Optional,
}
if err := dbclient.Client.FormInput.Update(newInput); err != nil {

View File

@ -1,4 +1,4 @@
<div class:col-1={col1} class:col-2={col2} class:col-3={col3} class:col-4={col4} class:col-3-4={col3_4}>
<div class:col-1={col1} class:col-2={col2} class:col-3={col3} class:col-4={col4} class:col-3-4={col3_4} style="--min-height: {minHeight}">
<label for="input" class="form-label">{label}</label>
<textarea id="input" class="form-input" placeholder="{placeholder}" bind:value on:change on:input></textarea>
</div>
@ -14,11 +14,13 @@
export let col4 = false;
export let col3_4 = false;
export let minHeight = "100px";
</script>
<style>
textarea {
width: 100%;
min-height: 100px;
min-height: var(--min-height);
}
</style>

View File

@ -19,13 +19,20 @@
</div>
</div>
<div class="row settings-row">
<Textarea col3_4={true} label="Placeholder" bind:value={data.placeholder}
<Textarea col3_4={true} label="Placeholder" bind:value={data.placeholder} minHeight="120px"
placeholder="Placeholder text for the field, just like this text" />
<Dropdown col4={true} label="Style" bind:value={data.style}>
<div class="col-4">
<div class="row">
<Dropdown col1={true} label="Style" bind:value={data.style}>
<option value=1 selected>Short</option>
<option value=2>Paragraph</option>
</Dropdown>
</div>
<div class="row">
<Checkbox label="Optional" bind:value={data.optional}/>
</div>
</div>
</div>
{#if windowWidth <= 950}
<div class="row">
@ -59,6 +66,7 @@
import Dropdown from "../form/Dropdown.svelte";
import Button from "../Button.svelte";
import Textarea from "../form/Textarea.svelte";
import Checkbox from "../form/Checkbox.svelte";
export let withCreateButton = false;
export let withSaveButton = false;

View File

@ -146,6 +146,7 @@
async function editInput(formId, inputId, data) {
let mapped = {...data, style: parseInt(data.style)};
console.log(mapped);
const res = await axios.patch(`${API_URL}/api/${guildId}/forms/${formId}/${inputId}`, mapped);
if (res.status !== 200) {
@ -183,6 +184,11 @@
}
forms = res.data || [];
forms.flatMap(f => f.inputs).forEach(i => i.optional = !i.required);
if (forms.length > 0) {
activeFormId = forms[0].form_id;
}
}
withLoadingScreen(async () => {

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc
github.com/TicketsBot/common v0.0.0-20220311020409-8068ba1c2ea3
github.com/TicketsBot/database v0.0.0-20220217133004-d190910ad66f
github.com/TicketsBot/database v0.0.0-20220531134243-da3320960cd4
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c
github.com/TicketsBot/worker v0.0.0-20220411233045-a69c2a4c8b30
github.com/apex/log v1.1.2

5
go.sum
View File

@ -13,14 +13,13 @@ github.com/TicketsBot/common v0.0.0-20220311020409-8068ba1c2ea3 h1:wcmBzDWg68gum
github.com/TicketsBot/common v0.0.0-20220311020409-8068ba1c2ea3/go.mod h1:SVwX6gKkxRCMbp+qwJIgvQiy/Ut0fUddexEqRB/NTzc=
github.com/TicketsBot/database v0.0.0-20200516170158-fd8a949aec2c/go.mod h1:eky4tBL+IZ0svPgTT0N/9i6j7ygHDQH3784DW+HgfcA=
github.com/TicketsBot/database v0.0.0-20210902172951-4e1f8ced84b7/go.mod h1:A4T2uQFIWC/ttCYpfgv7AkPjR09mMRgzG13lgoV/+aI=
github.com/TicketsBot/database v0.0.0-20220217133004-d190910ad66f h1:kBIHaAxyIGqxgwz/ZRggNGjyIdZ3ctWZqjJ9Svrn4L4=
github.com/TicketsBot/database v0.0.0-20220217133004-d190910ad66f/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
github.com/TicketsBot/database v0.0.0-20220531134243-da3320960cd4 h1:x8MkiL+E4w61otY7dJUSXTrqm0SqgsJbH8lovkSgZHk=
github.com/TicketsBot/database v0.0.0-20220531134243-da3320960cd4/go.mod h1:F57cywrZsnper1cy56Bx0c/HEsxQBLHz3Pl98WXblWw=
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s=
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c=
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261/go.mod h1:2zPxDAN2TAPpxUPjxszjs3QFKreKrQh5al/R3cMXmYk=
github.com/TicketsBot/worker v0.0.0-20220327033131-a7330f793044 h1:6yIgtfOJ9xjeZBgzXJT3B59NUcv75Kq0WDvfGhxW1HE=
github.com/TicketsBot/worker v0.0.0-20220327033131-a7330f793044/go.mod h1:ljMAQMiB5Gf3jgI9EGugAPAErjh2Ykwx3toD8z33KGY=
github.com/TicketsBot/worker v0.0.0-20220411233045-a69c2a4c8b30 h1:gfW/cIeA1DyH53q96Jqq+gqdIsuzIYYGHljwbHrChWY=
github.com/TicketsBot/worker v0.0.0-20220411233045-a69c2a4c8b30/go.mod h1:ljMAQMiB5Gf3jgI9EGugAPAErjh2Ykwx3toD8z33KGY=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=