Comments (4)
@gbj I'm not certain if this aligns with Leptos' principles. By the way, other frameworks address this issue with custom attributes for data binding (e.g., Angular's ngModel
). Could we envision something similar in Leptos?
E.g.
struct AddTodoInputData {
message: String,
}
#[server(AddTodo, "/api")]
pub async fn add_todo(data: AddTodoInputData) -> Result<(), ServerFnError> {
todo!()
}
#[component]
fn AddTodo() -> impl IntoView {
let add_todo = create_server_action::<AddTodo>();
let mut form_data = AddTodoInputData::default();
view! {
<ActionForm action=add_todo(form_data)>
<label>
<input type="text" model={form_data.message}/>
</label>
<input type="submit" value="Add"/>
</ActionForm>
}
}
Maybe this could even work before the wasm is loaded if the name
attribute is automatically generated from the model field name.
from leptos.
Sure, this would be possible if you required some additional derives on the struct, etc. (Field names are not strings, and can't be converted into strings, without some additional work) It's not something I'm interested in working on but if you'd like to see it, and would like to work on it, it could be great to start as a library and bring into the core if it seems useful to people.
I am not particularly interested in two-way data binding in general (and it can currently be implemented in user-land or in a library with a use:
directive), and definitely not by adding special behavior/new pseudo-attributes like <input model/>
or magic syntax like Angular's [(...)]
from leptos.
The short answer is "no." The medium answer is "I've tried to do something similar with checking arbitrarily nested children at compile time and isn't possible in a reasonable way that I can figure out."
The slightly longer/custom answer is that you could create a wrapping component that allows you to do it but probably not with a view-macro-like syntax.
from leptos.
Maybe, since there is already a generated AddTodo
struct, there could be additional helper fields on it?
E.g.: <input type="{AddTodo::title_field.input_type}" name="{AddTodo::title_field.name}"/>
from leptos.
Related Issues (20)
- `leptos_axum::redirect` fails if there is a delay issuing it inside a server function HOT 3
- `ActionForm` with complex args does not work with javascript disabled HOT 2
- Inconsistency in `aria-current="page"` behavior in `<A>`components HOT 1
- Rendering a component in a ProtectedRoute causes resources to be loaded twice
- Content inside of declarative shadow dom is not rendered HOT 5
- Bug: Unexpected Server-Side Resource Evaluation in Leptos 0.7-beta HOT 1
- Inconsistency in client-side query fragment handling HOT 3
- use:directive syntax doesn't work with generic params in Leptos 0.7 HOT 3
- leptos 0.6 fails to compile due to time dependency HOT 2
- GTK example doesn't build on latest main HOT 3
- Implement immediate/synchronous effects HOT 3
- Style does not uninstall when switching pages HOT 5
- template projects fail to build in version 0.6.14 HOT 2
- At … you tried to access a reactive value which was defined at …, but it has already been disposed.
- Server function param custom name HOT 1
- Nested routing broken
- Provided context not available inside `on:click` HOT 3
- Make any_spawner an optional + conditional dependency in tachys HOT 2
- Implement `ToHref` for `Rc<str>` HOT 2
- Allow to edit server meta context on SSR HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leptos.