66 lines
1.8 KiB
Plaintext
66 lines
1.8 KiB
Plaintext
package put
|
|
|
|
import "github.com/tigorlazuardi/redmage/views/utils"
|
|
import "fmt"
|
|
|
|
type SlugInputData struct {
|
|
Error string
|
|
Value string
|
|
Valid string
|
|
HXSwapOOB bool
|
|
}
|
|
|
|
templ SlugInput(data SlugInputData) {
|
|
<label
|
|
id="slug-input-form"
|
|
class="form-control"
|
|
if data.HXSwapOOB {
|
|
hx-swap-oob="true"
|
|
}
|
|
>
|
|
<div class="label">
|
|
<span
|
|
class={ utils.CXX(
|
|
"label-text", true,
|
|
"text-error", data.Error != "",
|
|
"text-success", data.Valid != "",
|
|
) }
|
|
>Slug Identifier</span>
|
|
<span class="label-text-alt italic font-bold text-primary max-xs:hidden">NOTE: Slug Identifier cannot be changed after creation</span>
|
|
</div>
|
|
<input
|
|
id="slug-input-field"
|
|
x-data={ fmt.Sprintf(`{ init() { $el.setCustomValidity(%q) } }`, data.Error) }
|
|
name="slug"
|
|
type="text"
|
|
@change="$el.setCustomValidity('')"
|
|
class={ utils.CXX(
|
|
"input input-bordered w-full", true,
|
|
"text-error input-error", data.Error != "",
|
|
"text-success input-success", data.Valid != "",
|
|
) }
|
|
hx-get="/htmx/devices/add/validate/slug"
|
|
hx-trigger="change, input delay:2s"
|
|
hx-target="#slug-input-form"
|
|
hx-target-error="#slug-input-form"
|
|
hx-swap="outerHTML"
|
|
placeholder="my-awesome-device"
|
|
title="Url Friendly Characters Only"
|
|
required
|
|
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 }
|
|
} else {
|
|
URL friendly Unique identifier for the device.
|
|
Value must be lowercase english alphabet and supported separator is only 'dash' (-) and 'underscores' (_).
|
|
}
|
|
</span>
|
|
</div>
|
|
</label>
|
|
}
|