Skip to content

Commit

Permalink
Add change support for company name and isin.
Browse files Browse the repository at this point in the history
Validate ISIN before save it.
  • Loading branch information
ejoepes committed Oct 22, 2024
1 parent 7a27e62 commit a39e0ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
wasm-logger = "0.2"
zip = { version = "0.5", default-features = false, features = ["deflate"]}
isin = "0.1.18"

[dev-dependencies]
ctor = "0.1"
Expand Down
32 changes: 29 additions & 3 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use futures_signals::{
signal::{Mutable, Signal, SignalExt},
signal_vec::{MutableVec, SignalVecExt},
};
use web_sys::HtmlElement;
use web_sys::{HtmlElement, HtmlInputElement};

use crate::{
css::TABLE_ROW,
Expand Down Expand Up @@ -121,11 +121,16 @@ impl Table {
Some(
html!("td", {
.child(
html!("input", {
html!("input" => HtmlInputElement, {
.attr("type", "text")
.attr("size", "40")
.attr("maxlength", "40")
.attr("value", &r.record.company.name)
.with_node!(element => {
.event(clone!(record => move |_: events::Change| {
record.lock_mut().record.company.name = element.value();
}))
})
})
)
})
Expand All @@ -140,15 +145,36 @@ impl Table {

fn company_isin_cell(record: &Mutable<Aeat720RecordInfo>) -> impl Signal<Item = Option<Dom>> {
record.signal_ref(clone!(record => move |r| {
let err_msg: Mutable<Option<&str>> = Mutable::new(None);
let isin_error_msg = "ISIN no valido";
if r.editable {
Some(
html!("td", {
.child(
html!("input", {
html!("input" => HtmlInputElement, {
.style("display", "block")
.attr("type", "text")
.attr("size", "12")
.attr("maxlength", "12")
.attr("value", &r.record.company.isin)
.with_node!(element => {
.event(clone!(record, err_msg => move |_: events::Input| {
let isin = element.value();
if let Ok(_) = isin::parse(&isin) {

Check warning on line 163 in src/table.rs

View workflow job for this annotation

GitHub Actions / Format & Clippy (1.80.1)

redundant pattern matching, consider using `is_ok()`
record.lock_mut().record.company.isin = isin;
*err_msg.lock_mut() = None;
} else {
*err_msg.lock_mut() = Some(isin_error_msg);
}
}))
})
})
)
.child(
html!("span", {
.style("color", "red")
.style("font-size", "small")
.text_signal(err_msg.signal_ref(|t| t.unwrap_or("")))
})
)
})
Expand Down

1 comment on commit a39e0ef

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.