Stop using tables for forms
This commit is contained in:
@@ -320,14 +320,36 @@ p {
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
/* Forms*/
|
||||
|
||||
.form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
text-align: left;
|
||||
max-width: 30em;
|
||||
text-align: initial;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form>* {
|
||||
display: block;
|
||||
margin-left: 3px;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
.form>label {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.form>input[type="submit"],
|
||||
.form>button[type="submit"] {
|
||||
align-self: end;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
|
||||
table:not(.form) {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
@@ -344,7 +366,7 @@ table:not(.form) {
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
tr:not(.form) {
|
||||
tr {
|
||||
border-bottom: 1px var(--separator) solid;
|
||||
}
|
||||
|
||||
@@ -353,16 +375,6 @@ tr>th {
|
||||
padding: 0.2em 0.5em;
|
||||
}
|
||||
|
||||
@media(max-width: 30em) {
|
||||
|
||||
/* Forms will be stacked on small screens */
|
||||
tr.form>td {
|
||||
float: left;
|
||||
width: 100%;
|
||||
padding: 0.5em;
|
||||
}
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 10px;
|
||||
border-bottom: 1px var(--separator) solid;
|
||||
@@ -416,12 +428,6 @@ details.request_patch {
|
||||
background-color: rgba(128, 0, 255, 0.1);
|
||||
}
|
||||
|
||||
/* Form fields */
|
||||
|
||||
.form_input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* BUTTONS */
|
||||
button,
|
||||
.button,
|
||||
@@ -583,7 +589,7 @@ input[type="date"] {
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background: var(--input_background);
|
||||
box-shadow: inset 1px 1px 2px -1px var(--shadow_color);
|
||||
/* box-shadow: inset 1px 1px 2px -1px var(--shadow_color); */
|
||||
padding: 3px 5px;
|
||||
color: var(--input_text);
|
||||
font-size: 1em;
|
||||
|
@@ -21,17 +21,11 @@
|
||||
<!-- The invisible username field is so browsers know which user the form was for -->
|
||||
<input type="text" autocomplete="username" value="{{.Username}}" style="display: none;" readonly="readonly"/>
|
||||
{{end}}
|
||||
<table class="form">
|
||||
<div class="form">
|
||||
{{range $field := .Fields}}
|
||||
<tr class="form">
|
||||
{{if eq $field.Type "textarea"}}
|
||||
<td colspan="2">
|
||||
{{$field.Label}}<br/>
|
||||
<textarea id="input_{{$field.Name}}" name="{{$field.Name}}" class="form_input" style="width: 100%; height: 10em; resize: vertical;">{{$field.DefaultValue}}</textarea>
|
||||
</td>
|
||||
{{else}}
|
||||
<td>{{$field.Label}}</td>
|
||||
<td>
|
||||
<label for="input_{{$field.Name}}">
|
||||
{{$field.Label}}
|
||||
</label>
|
||||
{{if eq $field.Type "text"}}
|
||||
<input id="input_{{$field.Name}}" name="{{$field.Name}}" value="{{$field.DefaultValue}}" type="text" class="form_input"/>
|
||||
{{else if eq $field.Type "number"}}
|
||||
@@ -44,6 +38,8 @@
|
||||
<input id="input_{{$field.Name}}" name="{{$field.Name}}" value="{{$field.DefaultValue}}" type="password" autocomplete="current-password" class="form_input"/>
|
||||
{{else if eq $field.Type "new-password"}}
|
||||
<input id="input_{{$field.Name}}" name="{{$field.Name}}" value="{{$field.DefaultValue}}" type="password" autocomplete="new-password" class="form_input"/>
|
||||
{{else if eq $field.Type "textarea"}}
|
||||
<textarea id="input_{{$field.Name}}" name="{{$field.Name}}" class="form_input" style="width: 100%; height: 10em; resize: vertical;">{{$field.DefaultValue}}</textarea>
|
||||
{{else if eq $field.Type "captcha"}}
|
||||
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
||||
<div class="g-recaptcha" data-theme="dark" data-sitekey="{{$field.CaptchaSiteKey}}"></div>
|
||||
@@ -60,41 +56,24 @@
|
||||
{{else if eq $field.Type "description"}}
|
||||
{{$field.DefaultValue}}
|
||||
{{end}}
|
||||
</td>
|
||||
{{end}}
|
||||
</tr>
|
||||
{{if or (ne $field.Description "") (eq $field.Separator true)}}
|
||||
<tr class="form">
|
||||
<td colspan="2">
|
||||
{{if ne $field.Description ""}}
|
||||
<div>
|
||||
{{$field.Description}}
|
||||
{{if eq $field.Separator true}}
|
||||
<hr/>
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<tr class="form">
|
||||
{{if eq .BackLink ""}}
|
||||
<td colspan="2" style="text-align: right;">
|
||||
{{if eq .SubmitRed true}}
|
||||
<input type="submit" value="{{.SubmitLabel}}" class="button_red" style="float: right;"/>
|
||||
<button type="submit" class="button_red">
|
||||
<i class="icon">send</i>
|
||||
{{.SubmitLabel}}
|
||||
</button>
|
||||
{{else}}
|
||||
<input type="submit" value="{{.SubmitLabel}}" class="button_highlight" style="float: right;"/>
|
||||
<button type="submit" class="button_highlight">
|
||||
<i class="icon">send</i>
|
||||
{{.SubmitLabel}}
|
||||
</button>
|
||||
{{end}}
|
||||
</td>
|
||||
{{else}}
|
||||
<td colspan="2" style="text-align: left;">
|
||||
<a href="{{.BackLink}}" class="button button_red" style="float: left;"/>Back</a>
|
||||
{{if eq .SubmitRed true}}
|
||||
<input type="submit" value="{{.SubmitLabel}}" class="button_red" style="float: right;"/>
|
||||
{{else}}
|
||||
<input type="submit" value="{{.SubmitLabel}}" class="button_highlight" style="float: right"/>
|
||||
{{end}}
|
||||
</td>
|
||||
{{end}}
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
{{.PostFormHTML}}
|
||||
{{end}}
|
||||
|
@@ -129,37 +129,25 @@ onMount(get_reporters);
|
||||
{#if creating}
|
||||
<div class="highlight_shaded">
|
||||
<form on:submit|preventDefault={create_reporter}>
|
||||
<table class="form">
|
||||
<tr>
|
||||
<td>E-mail address</td>
|
||||
<td><input type="text" bind:this={new_reporter_from_address}/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Mail server</td>
|
||||
<td><input type="text" bind:this={new_reporter_mail_server}/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td><input type="text" bind:this={new_reporter_name} value="Anonymous tip"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Status</td>
|
||||
<td>
|
||||
<div class="form">
|
||||
<label for="field_from_address">E-mail address</label>
|
||||
<input id="field_from_address" type="text" bind:this={new_reporter_from_address}/>
|
||||
<label for="field_mailserver">Mail server</label>
|
||||
<input id="field_mailserver" type="text" bind:this={new_reporter_mail_server}/>
|
||||
<label for="field_name">Name</label>
|
||||
<input id="field_name" type="text" bind:this={new_reporter_name} value="Anonymous tip"/>
|
||||
<label for="reporter_status">Status</label>
|
||||
<div>
|
||||
<input id="reporter_status_1" name="reporter_status" type="radio" bind:group={new_reporter_status} value="trusted" />
|
||||
<label for="reporter_status_1">Trusted</label>
|
||||
<br/>
|
||||
<input id="reporter_status_2" name="reporter_status" type="radio" bind:group={new_reporter_status} value="rejected" />
|
||||
<label for="reporter_status_2">Rejected</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<button class="button_highlight" type="submit" style="float: right;">
|
||||
</div>
|
||||
<button class="button_highlight" type="submit">
|
||||
<i class="icon">save</i> Save
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{/if}
|
||||
|
@@ -98,14 +98,11 @@ onMount(get_bans);
|
||||
{#if creating}
|
||||
<div class="highlight_shaded">
|
||||
<form on:submit|preventDefault={create_ban}>
|
||||
<table class="form">
|
||||
<tr>
|
||||
<td>IP address</td>
|
||||
<td><input type="text" bind:this={new_ban_address}/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Reason</td>
|
||||
<td>
|
||||
<div class="form">
|
||||
<label for="field_address">IP address</label>
|
||||
<input id="field_address" type="text" bind:this={new_ban_address}/>
|
||||
<label for="field_reason">Reason</label>
|
||||
<div id="field_reason">
|
||||
<input id="reason_unknown" name="reporter_type" type="radio" bind:group={new_ban_reason} value="unknown" />
|
||||
<label for="reason_unknown">unknown</label>
|
||||
<br/>
|
||||
@@ -123,16 +120,11 @@ onMount(get_bans);
|
||||
<br/>
|
||||
<input id="reason_malware" name="reporter_type" type="radio" bind:group={new_ban_reason} value="malware" />
|
||||
<label for="reason_malware">malware</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
</div>
|
||||
<button class="button_highlight" type="submit" style="float: right;">
|
||||
<i class="icon">save</i> Save
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{/if}
|
||||
|
@@ -51,7 +51,7 @@ let email_change = {
|
||||
fields: [
|
||||
{
|
||||
name: "new_email",
|
||||
label: "New e-mail address",
|
||||
label: "E-mail address",
|
||||
type: "email",
|
||||
default_value: window.user.email,
|
||||
description: `we will send an e-mail to the new address to
|
||||
@@ -83,7 +83,7 @@ let name_change = {
|
||||
fields: [
|
||||
{
|
||||
name: "new_username",
|
||||
label: "New name",
|
||||
label: "Name",
|
||||
type: "username",
|
||||
default_value: window.user.username,
|
||||
description: `changing your username also changes the name used to
|
||||
@@ -143,15 +143,27 @@ let delete_account = {
|
||||
|
||||
<section>
|
||||
<h2>Account settings</h2>
|
||||
<div class="highlight_shaded">
|
||||
<h3>Change password</h3>
|
||||
<Form config={password_change}></Form>
|
||||
</div>
|
||||
<br/>
|
||||
|
||||
<div class="highlight_shaded">
|
||||
<h3>Change e-mail address</h3>
|
||||
<Form config={email_change}></Form>
|
||||
</div>
|
||||
<br/>
|
||||
|
||||
<div class="highlight_shaded">
|
||||
<h3>Change name</h3>
|
||||
<Form config={name_change}></Form>
|
||||
</div>
|
||||
<br/>
|
||||
|
||||
<div class="highlight_shaded">
|
||||
<h3>Delete account</h3>
|
||||
<Form config={delete_account}></Form>
|
||||
</div>
|
||||
<br/>
|
||||
</section>
|
||||
|
@@ -131,23 +131,12 @@ let handle_errors = (response) => {
|
||||
{/if}
|
||||
|
||||
|
||||
<table class="form">
|
||||
<div class="form">
|
||||
{#each config.fields as field}
|
||||
<tr class="form">
|
||||
{#if field.type === "text_area"}
|
||||
<td colspan="2">
|
||||
{#if field.type !== "description"}
|
||||
<label for="input_{field.name}">
|
||||
{field.label}
|
||||
<br/>
|
||||
<textarea bind:this={field.binding}
|
||||
id="input_{field.name}"
|
||||
name="{field.name}"
|
||||
class="form_input"
|
||||
style="width: 100%; height: 10em; resize: vertical;"
|
||||
>{field.default_value}</textarea>
|
||||
</td>
|
||||
{:else if field.type !== "description"}
|
||||
<td>{field.label}</td>
|
||||
<td>
|
||||
</label>
|
||||
{#if field.type === "text"}
|
||||
<input bind:this={field.binding}
|
||||
id="input_{field.name}"
|
||||
@@ -155,6 +144,13 @@ let handle_errors = (response) => {
|
||||
value="{field.default_value}"
|
||||
type="text"
|
||||
class="form_input"/>
|
||||
{:else if field.type === "text_area"}
|
||||
<textarea bind:this={field.binding}
|
||||
id="input_{field.name}"
|
||||
name="{field.name}"
|
||||
class="form_input"
|
||||
style="width: 100%; height: 10em; resize: vertical;"
|
||||
>{field.default_value}</textarea>
|
||||
{:else if field.type === "number"}
|
||||
<input bind:this={field.binding}
|
||||
id="input_{field.name}"
|
||||
@@ -206,6 +202,7 @@ let handle_errors = (response) => {
|
||||
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
||||
<div class="g-recaptcha" data-theme="dark" data-sitekey="{field.captcha_site_key}"></div>
|
||||
{:else if field.type === "radio"}
|
||||
<div>
|
||||
{#each field.radio_values as val}
|
||||
<input bind:group={field.binding}
|
||||
id="input_{field.name}_choice_{val}"
|
||||
@@ -215,37 +212,26 @@ let handle_errors = (response) => {
|
||||
checked={val === field.default_value}/>
|
||||
<label for="input_{field.name}_choice_{val}">{val}</label><br/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</td>
|
||||
{/if}
|
||||
</tr>
|
||||
{#if field.description}
|
||||
<tr class="form">
|
||||
<td colspan="2">
|
||||
<div>
|
||||
{@html field.description}
|
||||
</td>
|
||||
</tr>
|
||||
</div>
|
||||
{/if}
|
||||
{#if field.separator}
|
||||
<tr class="form">
|
||||
<td colspan="2">
|
||||
<hr/>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
<!-- Submit button -->
|
||||
<tr class="form">
|
||||
<td colspan="2" style="text-align: right;">
|
||||
{#if config.submit_red}
|
||||
<button type="submit" class="button_red" style="float: right;">{@html config.submit_label}</button>
|
||||
<button type="submit" class="button_red">{@html config.submit_label}</button>
|
||||
{:else}
|
||||
<button type="submit" class="button_highlight" style="float: right;">{@html config.submit_label}</button>
|
||||
<button type="submit" class="button_highlight">{@html config.submit_label}</button>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
|
@@ -18,7 +18,6 @@ func (wc *WebController) adminGlobalsForm(td *TemplateData, r *http.Request) (f
|
||||
Name: "admin_globals",
|
||||
Title: "Pixeldrain global configuration",
|
||||
PreFormHTML: template.HTML("<p>Careful! The slightest typing error could bring the whole website down</p>"),
|
||||
BackLink: "/admin",
|
||||
SubmitLabel: "Submit",
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,6 @@ type Form struct {
|
||||
|
||||
Fields []Field
|
||||
|
||||
BackLink string // Empty for no back link
|
||||
SubmitLabel string // Label for the submit button
|
||||
SubmitRed bool // If the submit button should be red or green
|
||||
|
||||
@@ -53,9 +52,6 @@ type Field struct {
|
||||
// Text below the input field
|
||||
Description template.HTML
|
||||
|
||||
// Separates fields with a horizontal rule
|
||||
Separator bool
|
||||
|
||||
Type FieldType
|
||||
|
||||
// Only used when Type == FieldTypeCaptcha
|
||||
|
@@ -99,7 +99,6 @@ func (wc *WebController) registerForm(td *TemplateData, r *http.Request) (f Form
|
||||
Name: "username",
|
||||
Label: "Username",
|
||||
Description: "used for logging into your account",
|
||||
Separator: true,
|
||||
Type: FieldTypeUsername,
|
||||
}, {
|
||||
Name: "email",
|
||||
@@ -107,7 +106,6 @@ func (wc *WebController) registerForm(td *TemplateData, r *http.Request) (f Form
|
||||
Description: `not required. your e-mail address will only be
|
||||
used for password resets and important account
|
||||
notifications`,
|
||||
Separator: true,
|
||||
Type: FieldTypeEmail,
|
||||
}, {
|
||||
Name: "password",
|
||||
@@ -119,7 +117,6 @@ func (wc *WebController) registerForm(td *TemplateData, r *http.Request) (f Form
|
||||
Description: "you need to enter your password twice so we " +
|
||||
"can verify that no typing errors were made, which would " +
|
||||
"prevent you from logging into your new account",
|
||||
Separator: true,
|
||||
Type: FieldTypeNewPassword,
|
||||
}, {
|
||||
Name: "recaptcha_response",
|
||||
@@ -128,12 +125,10 @@ func (wc *WebController) registerForm(td *TemplateData, r *http.Request) (f Form
|
||||
"are not an evil robot that is trying to flood the " +
|
||||
"website with fake accounts. Please click the white box " +
|
||||
"to prove that you're not a robot",
|
||||
Separator: true,
|
||||
Type: FieldTypeCaptcha,
|
||||
CaptchaSiteKey: wc.captchaKey(),
|
||||
},
|
||||
},
|
||||
BackLink: "/",
|
||||
SubmitLabel: "Register",
|
||||
PostFormHTML: template.HTML("<p>Welcome to the club!</p>"),
|
||||
}
|
||||
@@ -181,7 +176,6 @@ func (wc *WebController) loginForm(td *TemplateData, r *http.Request) (f Form) {
|
||||
Type: FieldTypeCurrentPassword,
|
||||
},
|
||||
},
|
||||
BackLink: "/",
|
||||
SubmitLabel: "Login",
|
||||
PostFormHTML: template.HTML(
|
||||
`<p>If you don't have a pixeldrain account yet, you can ` +
|
||||
@@ -240,19 +234,16 @@ func (wc *WebController) passwordResetForm(td *TemplateData, r *http.Request) (f
|
||||
Label: "E-mail address",
|
||||
Description: `we will send a password reset link to this e-mail
|
||||
address`,
|
||||
Separator: true,
|
||||
Type: FieldTypeEmail,
|
||||
}, {
|
||||
Name: "recaptcha_response",
|
||||
Label: "Turing test (click the white box)",
|
||||
Description: "the reCaptcha turing test verifies that you " +
|
||||
"are not an evil robot that is trying hijack accounts",
|
||||
Separator: true,
|
||||
Type: FieldTypeCaptcha,
|
||||
CaptchaSiteKey: wc.captchaKey(),
|
||||
},
|
||||
},
|
||||
BackLink: "/login",
|
||||
SubmitLabel: "Submit",
|
||||
}
|
||||
|
||||
@@ -287,7 +278,6 @@ func (wc *WebController) passwordResetConfirmForm(td *TemplateData, r *http.Requ
|
||||
Description: "you need to enter your password twice so we " +
|
||||
"can verify that no typing errors were made, which would " +
|
||||
"prevent you from logging into your new account",
|
||||
Separator: true,
|
||||
Type: FieldTypeNewPassword,
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user