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 {
|
pub struct Datalist {
|
||||||
name: String,
|
name: String,
|
||||||
options: Vec<DatalistOption>,
|
options: Vec<DatalistOption>,
|
||||||
|
link_prefix: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Datalist {
|
impl Datalist {
|
||||||
|
@ -22,7 +23,7 @@ impl Datalist {
|
||||||
impl Render for Datalist {
|
impl Render for Datalist {
|
||||||
fn render(&self) -> Markup {
|
fn render(&self) -> Markup {
|
||||||
html! {
|
html! {
|
||||||
datalist #{ (self.name) "-datalist" } {
|
datalist #{ (self.name) "-datalist" } data-link-prefix=[&self.link_prefix] {
|
||||||
@for option in &self.options {
|
@for option in &self.options {
|
||||||
(option)
|
(option)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +50,7 @@ pub async fn items(pool: &PgPool) -> Result<Datalist, sqlx::Error> {
|
||||||
|
|
||||||
Ok(Datalist {
|
Ok(Datalist {
|
||||||
name: "items".to_string(),
|
name: "items".to_string(),
|
||||||
|
link_prefix: Some("/item/".to_string()),
|
||||||
options: items
|
options: items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| DatalistOption {
|
.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> {
|
pub async fn item_classes(pool: &PgPool) -> Result<Datalist, sqlx::Error> {
|
||||||
Ok(Datalist {
|
Ok(Datalist {
|
||||||
name: "item-classes".to_string(),
|
name: "item-classes".to_string(),
|
||||||
|
link_prefix: Some("/item-class/".to_string()),
|
||||||
options: manage::item_class::get_all(pool)
|
options: manage::item_class::get_all(pool)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -19,7 +19,15 @@
|
||||||
if (selected === null)
|
if (selected === null)
|
||||||
hint.innerText = ""
|
hint.innerText = ""
|
||||||
else {
|
else {
|
||||||
|
const linkPrefix = input.list.dataset.linkPrefix;
|
||||||
|
if (linkPrefix === undefined) {
|
||||||
hint.innerHTML = selected.innerHTML
|
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 => {
|
Array.from(document.getElementsByClassName("datalist-hint")).forEach(hint => {
|
||||||
|
|
Loading…
Reference in a new issue