Implement form submissions#188
Conversation
c0564e0 to
4ecfadc
Compare
|
Just a note that I going to be offline for next 3-4 days. Will review when I'm back! |
dfb6847 to
520400b
Compare
520400b to
4dd97c4
Compare
4dd97c4 to
2a0564b
Compare
|
I have rebased this on top of latest |
2a0564b to
c06b679
Compare
|
Have rebased and force pushed again. Sorry for the delay in review. Will get to this soon! |
c06b679 to
58d4b73
Compare
58d4b73 to
6252cfd
Compare
638eb10 to
aeb27b4
Compare
Signed-off-by: Nico Burns <nico@nicoburns.com>
Signed-off-by: Nico Burns <nico@nicoburns.com>
aeb27b4 to
1eb34ca
Compare
nicoburns
left a comment
There was a problem hiding this comment.
@kokoISnoTarget I've left you some review comments. However, in the interest of 1. getting this merged and 2. avoiding conflicts, I'm going to merge this as-is and iterate on top of it.
| for id in self.form_nodes.borrow().iter() { | ||
| doc.reset_form_owner(*id); | ||
| } |
There was a problem hiding this comment.
html5ever actually computes the form associations for us (https://docs.rs/html5ever/latest/html5ever/interface/trait.TreeSink.html#method.associate_with_form). Perhaps we should use that?
(not sure though, as we'll need to implement this ourselves for dioxus-native anyway)
There was a problem hiding this comment.
I didn't actually see this, but we need to reset all form controls anyways because html5ever does not find associations using the form attr:
<button form="form1">Test</button>
<form id="form1">
</form>|
|
||
| #[derive(Debug, Clone)] | ||
| pub enum DocumentResource { | ||
| String(String), |
There was a problem hiding this comment.
What is the purpose of the String variant? It never seems to be used? Perhaps url and document_resource should just be a blitz_traits::net::Request?
| pub fn new_with_root(doc: &'a BaseDocument, root: usize) -> Self { | ||
| TreeTraverser { | ||
| doc, | ||
| stack: vec![root], |
There was a problem hiding this comment.
Nit: Consider pre-allocating more stack space. Perhaps a capacity of 20?
|
|
||
| #[derive(Clone)] | ||
| /// An pre-order tree traverser for a [BaseDocument](crate::document::BaseDocument). | ||
| pub struct TreeTraverser<'a> { | ||
| doc: &'a BaseDocument, | ||
| stack: Vec<usize>, | ||
| } | ||
|
|
There was a problem hiding this comment.
Can we move these "traversers" into their own traversal module please?
These also duplicate the method starting with iter_children_mut, iter_subtree_mut, next_node, etc in document.rs. The approach is slightly different, but we'll probably want to deduplicate this at some point. Could you please review those methods and let me know any thoughts you have on how we might unify these APIs.
|
|
||
| pub changed: HashSet<usize>, | ||
|
|
||
| pub controls_to_form: HashMap<usize, usize>, |
There was a problem hiding this comment.
Can you add a doc comment on this field please? I assume the key is the NodeId of the form control and the value is the NodeId of the form itself?
There was a problem hiding this comment.
Can you add a doc comment on this field please?
Sure thing.
I assume the key is the
NodeIdof the form control and the value is theNodeIdof the form itself?
You assumed correctly.
| pub struct NavigationHandler(String); | ||
| impl NavigationHandler { | ||
| pub fn boxed(url: impl Into<String>) -> Box<Self> { | ||
| Box::new(Self(url.into())) | ||
| } | ||
| } | ||
| impl NetHandler<Resource> for NavigationHandler { | ||
| fn bytes(self: Box<Self>, doc_id: usize, bytes: Bytes, callback: SharedCallback<Resource>) { | ||
| callback.call( | ||
| doc_id, | ||
| Ok(Resource::Navigation { | ||
| url: self.0, | ||
| document: bytes, | ||
| }), | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
I don't think blitz-dom should handle the network call when navigating to a new document. Not least because a custom NavigationProvider may want to implement their own loading logic which is different to that implemented in the NetProvider.
The way I think this should work is that blitz-dom just calls into the navigation provider with the "request" to navigate (be that from clicking on a link or submitting a form), and then the navigation provider can do whatever it likes. In practice, the navigation provider will have it's own reference to the (same) network provider which it can use to fetch the document.
There was a problem hiding this comment.
Yea, this should be removed anyways, as it's a leftover from a test implementation.
| enum FormMethod { | ||
| Get, | ||
| Post, | ||
| Dialog, |
There was a problem hiding this comment.
What is the "dialog" method? Can't find any references to this.
There was a problem hiding this comment.
This is intended to close a dialog.
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method
Implements basic form submissions (fixes #178)
I tried following the specification, where it made sense.
Things that are missing are:
DomEvents: submit, a click event when implicitly submitting and formdata when constructing the entry list.<select>multipart/form-data