Redmage/views/devicesview/put/slug_input.templ

79 lines
2 KiB
Plaintext
Raw Normal View History

2024-05-08 10:10:23 +07:00
package put
2024-05-07 16:48:15 +07:00
import "github.com/tigorlazuardi/redmage/views/utils"
import "fmt"
type SlugInputData struct {
2024-05-08 10:10:23 +07:00
Error string
Value string
Valid string
HXSwapOOB bool
Disabled bool
DisabledText string
2024-05-07 16:48:15 +07:00
}
templ SlugInput(data SlugInputData) {
2024-05-07 20:51:00 +07:00
<label
id="slug-input-form"
class="form-control"
if data.HXSwapOOB {
hx-swap-oob="true"
}
>
2024-05-07 16:48:15 +07:00
<div class="label">
<span
class={ utils.CXX(
"label-text", true,
"text-error", data.Error != "",
"text-success", data.Valid != "",
) }
>Slug Identifier</span>
2024-05-07 16:48:15 +07:00
</div>
<input
id="slug-input-field"
2024-05-08 10:10:23 +07:00
if !data.Disabled {
x-data={ fmt.Sprintf(`{ init() { $el.setCustomValidity(%q) } }`, data.Error) }
}
2024-05-07 16:48:15 +07:00
name="slug"
type="text"
2024-05-08 10:10:23 +07:00
if !data.Disabled {
@change="$el.setCustomValidity('')"
}
2024-05-07 16:48:15 +07:00
class={ utils.CXX(
"input input-bordered", true,
"text-error", data.Error != "",
"text-success", data.Valid != "",
"input-error", data.Error != "",
"input-success", data.Valid != "",
) }
2024-05-08 10:10:23 +07:00
if data.Disabled {
disabled
} else {
hx-post="/htmx/devices/add/validate/slug"
hx-trigger="change, input delay:2s"
hx-target="#slug-input-form"
hx-target-409="#slug-input-form"
hx-swap="outerHTML"
placeholder="my-awesome-device"
title="Url Friendly Characters Only"
required
}
2024-05-07 16:48:15 +07:00
value={ data.Value }
/>
<div class="label">
<span class={ utils.CXX("label-text", true, "text-error", data.Error != "", "text-success", data.Valid != "") }>
if data.Valid != "" {
{ data.Valid }
} else if data.Error != "" {
{ data.Error }
2024-05-08 10:10:23 +07:00
} else if data.DisabledText != "" {
{ data.DisabledText }
2024-05-07 16:48:15 +07:00
} else {
URL friendly Unique identifier for the device.
2024-05-07 20:51:00 +07:00
Value must be lowercase english alphabet and supported separator is only 'dash' (-) and 'underscores' (_).
2024-05-07 16:48:15 +07:00
}
</span>
</div>
</label>
}