Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit input attributes to inputs with a valid type attribute #275

Open
anp opened this issue May 7, 2021 · 0 comments
Open

Limit input attributes to inputs with a valid type attribute #275

anp opened this issue May 7, 2021 · 0 comments
Labels
dom Related to moxie-dom and associated crates mox Related to our mockery of XML

Comments

@anp
Copy link
Owner

anp commented May 7, 2021

Example: only file inputs should statically allow the accept attribute, i.e. this should be a compile error:

input().type_("checkbox").accept("*").build()

I think this can be done by making Input<Ty: InputType> and some zero-sized types which implement InputType. Then you'd limit the impls to only the input types that are valid:

impl Input<File> {
    fn accept(self, a: &str) -> Self { ... }
}

To do this, we need the type_() function on all elements to "fill in" the generic parameter. The question I have right now is how to get the right type info at compile time while preserving the same mox syntax as we currently have:

mox! { <input type="file" accept="*"></input> }

// expands to
input()
    .type_("file")
    .accept("*")
    .build()

One possible approach would be to use a const generic string once thats available:

input()
    .type_::<"file">()
    .accept("*")
    .build()

Another would be to make the function generic over a ZST argument, but lose the "stringness" of the type attribute:

input()
    .type_(File)
    .accept("*")
    .build()

Both of these APIs could be supported with the same surface syntax in mox but adding a bunch of web-specific constants isn't great when the macro should work across platforms.

If we don't special-case the macro and we require a different syntax for invoking the type, then we lose a bit of HTML/XML familiarity which is some of the point of the macro in the first place.

@anp anp added mox Related to our mockery of XML dom Related to moxie-dom and associated crates labels May 7, 2021
@anp anp modified the milestone: moxie-dom 1.0 May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dom Related to moxie-dom and associated crates mox Related to our mockery of XML
Projects
None yet
Development

No branches or pull requests

1 participant