Optional form responses
This commit is contained in:
parent
9722b82598
commit
4a121f6b63
@ -13,6 +13,7 @@ type inputCreateBody struct {
|
|||||||
Style component.TextStyleTypes `json:"style"`
|
Style component.TextStyleTypes `json:"style"`
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Placeholder *string `json:"placeholder"`
|
Placeholder *string `json:"placeholder"`
|
||||||
|
Optional bool `json:"optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateInput(ctx *gin.Context) {
|
func CreateInput(ctx *gin.Context) {
|
||||||
@ -69,11 +70,11 @@ func CreateInput(ctx *gin.Context) {
|
|||||||
// 2^30 chance of collision
|
// 2^30 chance of collision
|
||||||
customId := utils.RandString(30)
|
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 {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(200, database.FormInput{
|
ctx.JSON(200, database.FormInput{
|
||||||
Id: formInputId,
|
Id: formInputId,
|
||||||
@ -82,13 +83,14 @@ func CreateInput(ctx *gin.Context) {
|
|||||||
Style: uint8(data.Style),
|
Style: uint8(data.Style),
|
||||||
Label: data.Label,
|
Label: data.Label,
|
||||||
Placeholder: data.Placeholder,
|
Placeholder: data.Placeholder,
|
||||||
|
Required: !data.Optional,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *inputCreateBody) Validate(ctx *gin.Context) bool {
|
func (b *inputCreateBody) Validate(ctx *gin.Context) bool {
|
||||||
if b.Style != component.TextStyleShort && b.Style != component.TextStyleParagraph {
|
if b.Style != component.TextStyleShort && b.Style != component.TextStyleParagraph {
|
||||||
ctx.JSON(400, utils.ErrorStr("Invalid style"))
|
ctx.JSON(400, utils.ErrorStr("Invalid style"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(b.Label) == 0 || len(b.Label) > 45 {
|
if len(b.Label) == 0 || len(b.Label) > 45 {
|
||||||
@ -115,5 +117,5 @@ func getFormInputCount(formId int) (int, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(inputs), nil
|
return len(inputs), nil
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ func UpdateInput(ctx *gin.Context) {
|
|||||||
Style: uint8(data.Style),
|
Style: uint8(data.Style),
|
||||||
Label: data.Label,
|
Label: data.Label,
|
||||||
Placeholder: data.Placeholder,
|
Placeholder: data.Placeholder,
|
||||||
|
Required: !data.Optional,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.FormInput.Update(newInput); err != nil {
|
if err := dbclient.Client.FormInput.Update(newInput); err != nil {
|
||||||
|
@ -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>
|
<label for="input" class="form-label">{label}</label>
|
||||||
<textarea id="input" class="form-input" placeholder="{placeholder}" bind:value on:change on:input></textarea>
|
<textarea id="input" class="form-input" placeholder="{placeholder}" bind:value on:change on:input></textarea>
|
||||||
</div>
|
</div>
|
||||||
@ -14,11 +14,13 @@
|
|||||||
export let col4 = false;
|
export let col4 = false;
|
||||||
|
|
||||||
export let col3_4 = false;
|
export let col3_4 = false;
|
||||||
|
|
||||||
|
export let minHeight = "100px";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
textarea {
|
textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-height: 100px;
|
min-height: var(--min-height);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
@ -19,12 +19,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row settings-row">
|
<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" />
|
placeholder="Placeholder text for the field, just like this text" />
|
||||||
<Dropdown col4={true} label="Style" bind:value={data.style}>
|
<div class="col-4">
|
||||||
<option value=1 selected>Short</option>
|
<div class="row">
|
||||||
<option value=2>Paragraph</option>
|
<Dropdown col1={true} label="Style" bind:value={data.style}>
|
||||||
</Dropdown>
|
<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>
|
</div>
|
||||||
|
|
||||||
{#if windowWidth <= 950}
|
{#if windowWidth <= 950}
|
||||||
@ -59,6 +66,7 @@
|
|||||||
import Dropdown from "../form/Dropdown.svelte";
|
import Dropdown from "../form/Dropdown.svelte";
|
||||||
import Button from "../Button.svelte";
|
import Button from "../Button.svelte";
|
||||||
import Textarea from "../form/Textarea.svelte";
|
import Textarea from "../form/Textarea.svelte";
|
||||||
|
import Checkbox from "../form/Checkbox.svelte";
|
||||||
|
|
||||||
export let withCreateButton = false;
|
export let withCreateButton = false;
|
||||||
export let withSaveButton = false;
|
export let withSaveButton = false;
|
||||||
|
@ -146,6 +146,7 @@
|
|||||||
|
|
||||||
async function editInput(formId, inputId, data) {
|
async function editInput(formId, inputId, data) {
|
||||||
let mapped = {...data, style: parseInt(data.style)};
|
let mapped = {...data, style: parseInt(data.style)};
|
||||||
|
console.log(mapped);
|
||||||
|
|
||||||
const res = await axios.patch(`${API_URL}/api/${guildId}/forms/${formId}/${inputId}`, mapped);
|
const res = await axios.patch(`${API_URL}/api/${guildId}/forms/${formId}/${inputId}`, mapped);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
@ -183,6 +184,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
forms = res.data || [];
|
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 () => {
|
withLoadingScreen(async () => {
|
||||||
|
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
|||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc
|
github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc
|
||||||
github.com/TicketsBot/common v0.0.0-20220311020409-8068ba1c2ea3
|
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/logarchiver v0.0.0-20220326162808-cdf0310f5e1c
|
||||||
github.com/TicketsBot/worker v0.0.0-20220411233045-a69c2a4c8b30
|
github.com/TicketsBot/worker v0.0.0-20220411233045-a69c2a4c8b30
|
||||||
github.com/apex/log v1.1.2
|
github.com/apex/log v1.1.2
|
||||||
|
5
go.sum
5
go.sum
@ -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/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-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-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-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 h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s=
|
||||||
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c=
|
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 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=
|
||||||
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261/go.mod h1:2zPxDAN2TAPpxUPjxszjs3QFKreKrQh5al/R3cMXmYk=
|
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 h1:gfW/cIeA1DyH53q96Jqq+gqdIsuzIYYGHljwbHrChWY=
|
||||||
github.com/TicketsBot/worker v0.0.0-20220411233045-a69c2a4c8b30/go.mod h1:ljMAQMiB5Gf3jgI9EGugAPAErjh2Ykwx3toD8z33KGY=
|
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=
|
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user