#[derive(AdminUpdateForm)]
{
// Attributes available to this derive:
#[update_form]
#[update_field]
}
Expand description
Derive the AdminUpdateForm trait
§Attributes
update_form- struct attribute, requiredprimary_keys- the type of the primary key(s), required if no primary key is indicated in the fieldsentity_name- name of the entity (database table), requiredupdate_query- A handler which persists the entity, optional, defaults to a Postgres query constructed by the macro
update_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 frontendprimary_key- optional, Marking the field as primary key, will be used for the automatic update query and makes the field typeHiddenFieldby default
§Example
This example shows all available attributes and values
// TODO: Create a test for it
#[derive(Clone, Debug, AdminUpdateForm, serde::Deserialize, serde::Serialize, sqlx::FromRow)]
#[update_form(entity_name = "test", primary_keys = i32, update_query = update_entity(state).await, get_query = get_entity(state).await)]
pub struct TestEntityUpdateForm {
#[update_field(primary_key)]
id: i32,
#[update_field(
required,
default = "Test Entity",
label = "Entity Name",
form_field = CustomNameSelect::new(),
)]
name: String,
}
async fn update_entity<S: quokka::state::State + quokka::state::ProvideState<Database>>(state: &S) -> quokka::Result<()> {
// Update the entity here
Ok(())
}
async fn get_entity<S: quokka::state::State + quokka::state::ProvideState<Database>>() -> quokka::Result<TestEntityUpdateForm> {
todo!("Implement getting the entity")
}