#[derive(AdminCreateForm)]
{
// Attributes available to this derive:
#[create_form]
#[create_field]
}
Expand description
Derive the AdminCreateForm trait
§Attributes
create_form- struct attribute, requiredentity_name- name of the entity (database table), requiredcreate_query- A handler which persists the entity, optional, defaults to a Postgres query constructed by the macro
create_field- field attribute, optionalrequired- optional, Make the field is required (only used in the frontend, losening this will require theOption<T>type in the struct)default- optional, The default value for the entitylabel- optional, The label for the inputform_field- optional, The form field type which is rendered in the frontend
§Example
This example shows all available attributes and values
// TODO: Create a test for it
#[derive(Clone, Debug, AdminCreateForm, serde::Deserialize, serde::Serialize, sqlx::FromRow)]
#[create_form(entity_name = "test", create_query = create_entity(state).await)]
pub struct TestEntityCreateForm {
#[create_field(
required, // Whether the field is required or not
default = "Test Entity", // The default value for the entity
label = "Entity Name", // The label for the input
form_field = CustomNameSelect::new(), // The form field type which is rendered in the frontend
)]
name: String,
}
async fn create_entity<S: quokka::state::State + quokka::state::ProvideState<Database>>(state: &S) -> quokka::Result<()> {
// Persist the entity here
Ok(())
}