Allow displaying datalist hint as link
This commit is contained in:
parent
8aff438f98
commit
8e61f34b3f
|
@ -11,6 +11,7 @@ use crate::manage;
|
|||
pub struct Datalist {
|
||||
name: String,
|
||||
options: Vec<DatalistOption>,
|
||||
link_prefix: Option<String>,
|
||||
}
|
||||
|
||||
impl Datalist {
|
||||
|
@ -22,7 +23,7 @@ impl Datalist {
|
|||
impl Render for Datalist {
|
||||
fn render(&self) -> Markup {
|
||||
html! {
|
||||
datalist #{ (self.name) "-datalist" } {
|
||||
datalist #{ (self.name) "-datalist" } data-link-prefix=[&self.link_prefix] {
|
||||
@for option in &self.options {
|
||||
(option)
|
||||
}
|
||||
|
@ -49,6 +50,7 @@ pub async fn items(pool: &PgPool) -> Result<Datalist, sqlx::Error> {
|
|||
|
||||
Ok(Datalist {
|
||||
name: "items".to_string(),
|
||||
link_prefix: Some("/item/".to_string()),
|
||||
options: items
|
||||
.iter()
|
||||
.map(|i| DatalistOption {
|
||||
|
@ -62,6 +64,7 @@ pub async fn items(pool: &PgPool) -> Result<Datalist, sqlx::Error> {
|
|||
pub async fn item_classes(pool: &PgPool) -> Result<Datalist, sqlx::Error> {
|
||||
Ok(Datalist {
|
||||
name: "item-classes".to_string(),
|
||||
link_prefix: Some("/item-class/".to_string()),
|
||||
options: manage::item_class::get_all(pool)
|
||||
.await?
|
||||
.into_iter()
|
||||
|
|
|
@ -19,7 +19,15 @@
|
|||
if (selected === null)
|
||||
hint.innerText = ""
|
||||
else {
|
||||
const linkPrefix = input.list.dataset.linkPrefix;
|
||||
if (linkPrefix === undefined) {
|
||||
hint.innerHTML = selected.innerHTML
|
||||
} else {
|
||||
let link = document.createElement("a")
|
||||
link.href = `${linkPrefix}${input.value}`
|
||||
link.innerHTML = selected.innerHTML
|
||||
hint.appendChild(link)
|
||||
}
|
||||
}
|
||||
}
|
||||
Array.from(document.getElementsByClassName("datalist-hint")).forEach(hint => {
|
||||
|
|
Loading…
Reference in a new issue