form-yew

Crates.ioform-yew
lib.rsform-yew
version0.1.1
sourcesrc
created_at2022-11-07 08:05:23.8252
updated_at2022-11-13 02:47:47.31
descriptiona macro to help with forms in yew
homepagehttps://github.com/sasacocic/yew_form_derive
repositoryhttps://github.com/sasacocic/yew_form_derive
max_upload_size
id707087
size19,568
Sasa Cocic-Banjanac (sasacocic)

documentation

https://github.com/sasacocic/yew_form_derive

README

THIS CRATE SHOULDN'T BE USED IN IT'S CURRENT STATE

as it stands please don't use this crate for well basically anything. I'm using it for http://rustjobs.io atm. The plan is to improve the create overtime, and make it more general to handle more use cases.

fix this soon

  • if bool type is used then make it a bool if it's a string make it a string if the ele attribute is "checkbox"

This is a work in progress

WARNING this crate is badly documented and, becuase of that it makes it hard to use

TODOS

  • Add documentation for doc.rs

What is this

  • this is a macro to help with forms in yew. How it works
use yew_form_derive::YewForm;

// TODO: idk if this is a minial example
// this create input elements that can be used in a from
// to use these elements use the context provided by this
// macro
#[derive(YewForm, PartialEq)]
pub struct AdvertiseForm {
    pub company: String,
    pub position: String,
    pub salary_range: String,
    pub link_to_apply: String, // better suited as a URL type
    #[ele = "textarea"]
    pub description: String,
}


// later on in another file or the same on

...

#[function_component(FormConsumer)]
pub fn consumer() -> Html {
    let form = use_context::<AdvertiseFormProvider>().expect("an advertiser form");

    let input_style = "text-xl sm:text-5xl bg-transparent border-black border p-2.5 rounded-lg";
    html! {
        <form>
            <Company class={input_style} />
            <Position class={input_style} />
            <Salary_range class={input_style} />
            <Description class={input_style}/>
            <Link_to_apply class={input_style}/>

            <button type="submit">
                {"Checkout ->"}
            </button>
        </form>
    }
}

#[function_component(AdvertisePage)]
pub fn advertise_page() -> Html {
    html! {
        <AdvertiseFormProvider>
            <FormConsumer />
        </AdvertiseFormProvider>
    }
}
Commit count: 7

cargo fmt