Redmage/views/devices/put/name_input.templ

45 lines
1.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 NameInputData struct {
2024-05-08 10:10:23 +07:00
Error string
Value string
DisableValidation bool
2024-05-07 16:48:15 +07:00
}
templ NameInput(data NameInputData) {
<label id="name-input-form" class="form-control">
2024-05-07 16:48:15 +07:00
<div class="label">
<span
class={ utils.CXX("label-text", true, "text-error", data.Error != "") }
>Name</span>
</div>
<input
id="name-input-field"
2024-05-08 10:10:23 +07:00
if !data.DisableValidation {
required
x-data={ fmt.Sprintf(`{ init() { $el.setCustomValidity(%q) } }`, data.Error) }
2024-05-08 11:19:14 +07:00
hx-get="/htmx/devices/add/validate/name"
2024-05-08 10:10:23 +07:00
hx-include="[name='slug']"
hx-trigger="change"
hx-target="#name-input-form"
hx-swap="outerHTML"
placeholder="My Awesome Device"
}
2024-05-07 16:48:15 +07:00
name="name"
type="text"
class={ utils.CXX("input input-bordered", true, "input-error", data.Error != "") }
value={ data.Value }
/>
<div class="label">
if data.Error != "" {
<span class="label-text text-error">{ data.Error }</span>
} else {
<span class="label-text">The display name for the device. You can use non-english characters for the name.</span>
2024-05-07 16:48:15 +07:00
}
</div>
</label>
}