Files

66 lines
1.9 KiB
Svelte
Raw Permalink Normal View History

2026-01-08 13:10:18 +02:00
<script>
2026-01-08 18:50:32 +02:00
import SchemaLayout from "../../layouts/SchemaLayout.svelte";
2026-01-08 13:10:18 +02:00
import { post } from "../../modules/remote";
import { getApp } from "../../app";
2026-01-08 15:19:08 +02:00
let { channel, user, data, newRank } = $props();
2026-01-08 13:10:18 +02:00
let name = $state("");
let alias = $state("");
const app = getApp();
2026-01-08 15:19:08 +02:00
function handleCreate(e) {
2026-01-08 13:10:18 +02:00
e.preventDefault();
post(
app.url("fields"),
{
schemaId: data.schema.id,
name: name,
alias: alias,
fieldType: data.type,
},
(data, err) => {
if (err.isEmpty()) {
Turbo.visit(app.url("fields/edit/" + data.field.id));
} else {
console.log(err);
}
},
);
}
</script>
2026-01-08 18:50:32 +02:00
<SchemaLayout {body} {channel} {user}></SchemaLayout>
2026-01-08 13:10:18 +02:00
{#snippet body()}
<h3 class="header-small mb-4 mt-5">Create a <em>{data.type}</em> field</h3>
2026-01-08 15:19:08 +02:00
<form onsubmit={handleCreate}>
2026-01-08 13:10:18 +02:00
<fieldset>
<label>
Name
<input
bind:value={name}
placeholder="ex. Description"
minlength="2"
maxlength="30"
required
/>
</label>
<label>
Alias
<input
bind:value={alias}
placeholder="ex. description"
minlength="2"
maxlength="30"
required
aria-describedby="alias-helper"
/>
<small id="alias-helper">
Developers will use this to reference the field
</small>
</label>
</fieldset>
<button type="submit">Create</button>
</form>
{/snippet}