Closed ltfschoen closed 1 year ago
Remove the move
keyword from the closure in the iterator:
for (0..indexes.len()-1).map(|index|
Instead of:
for (0..indexes.len()-1).map(move |index|
If that doesn't work, you'll need to declare the event handlers inside the map
instead of trying to capture copies from the outside.
let onmouseover = state.bind(move |state, e: MouseEvent<InputElement>| {
let _ = e.target().focus();
});
Can be just:
let onmouseover = |e: MouseEvent<InputElement>| {
let _ = e.target().focus();
};
Since it doesn't do anything with the state.
On latest master I've shadowed the focus
method to not return a result (it's guaranteed to work) so you can make it even simpler:
let onmouseover = |e: MouseEvent<InputElement>| e.target().focus();
Not sure what that -1
is doing there, ..
is an exclusive range already, 0..5
iterates over 5 values: 0
,1
,2
,3
, and 4
.
@ltfschoen I made a discord server: https://discord.gg/tgNX5VYSWF
Feel free to ask Rust-related questions there. I'm happy to answer them, but I'd like to keep the Issues on GH clean for, well, issues and discussions related to Kobold, not stuff like move semantics or ownership rules of Rust :upside_down_face:.
(Also not at the keyboard a lot today so might be slow).
thanks, all your feedback worked and in this commit
In this "draft" Pull Request, i am getting the following errors in the last commit since trying to introduce new changes mentioned below. the last commit where it was working before any of these changes is this one
click to show error
```bash error[E0507]: cannot move out of `onchange`, a captured variable in an `FnMut` closure --> examples/invoice/src/main.rs:342:42 | 299 | let onchange = state.bind(move |state, e: EventThe most obvious solution for me was to update
struct Event
and give it#[derive(Copy)]
as shown below:but that gave error:
Update: I realised when I did this that I was still using kobold "0.6.0" instead of "0.7.0", which doesn't have the same code, but even after I updated to "0.7.0" I still got the same errors
To provide some context of what I'm doing, I'm customizing the
EntryView
component, so it gets thestate.details.table
(which is a table like in its mock here where it just has a first row of label columns and second row with corresponding data columns.Then here I populate a
valid_labels
Vec
with its labels from the first row, then populate avalues
Vec
with the data from the second row, and I populate anindexes
Vec
with the corresponding indexes of each column where the data came from (since i need to loop through them withfor (0..indexes.len()-1).map(move |index|
in theview!
. So each of thoseVec
have the same length.Then I use
Branch2::A
if they are editing, orBranch2::B
otherwise.I'm having trouble in
Branch2::A
for editing at the moment, relevant code snippet below:I try to use
for (0..indexes.len()-1).map(move |index|
to generate an editable input field for each column of data. I try to store a reference to theindex
in a data attribute like thisdata_index={ ref index.to_string() }
. I show the current value being edited in the input field withvalue={ ref values[index] }
as shown. Note: I tried to use the HTML syntaxdata-index
there, but that gave an errorexpected expression
, hence why i useddata_index
(with an_
underscore instead of dash-
). Maybe I also need to add thatdata-*
attribute in the Kobold macros here https://github.com/maciejhirsz/kobold/blob/master/crates/kobold_macros/src/gen/element.rs#L260Then since there are multiple input fields (for each column from the table), I need the
onchange
handler to cater for each one, so I get the value of thedata_index
attribute from the input element, since it contains theindex
that corresponds to the column with the data that we want to populate if there are any changes, so I can use theindex
variable like thisstate.details.table.rows[0][index]
. code snippet belowHere I'm not sure whether I should use
get_attribute("data_index")
orget_attribute("data-index")
(i.e. dash or underscore).The errors shown above disappear if I comment out the following code, but I want to use that code: