use topcoat::context::Cx;
use crate::{
form::{FieldError, FormValues},
schema::{Field, Schema},
};
pub trait ActionInput: Sized + Send + 'static {
fn schema() -> Schema;
fn parse(cx: &Cx, values: &FormValues) -> Result<Self, Vec<FieldError>>;
}
impl ActionInput for () {
fn schema() -> Schema {
Schema::empty()
}
fn parse(_cx: &Cx, _values: &FormValues) -> Result<Self, Vec<FieldError>> {
Ok(())
}
}
#[doc(hidden)]
pub fn required_input(field: impl Into<Field>) -> Field {
let mut field = field.into();
field.set_required(true);
field
}
pub(crate) const RESERVED_KEYS: [&str; 3] = [crate::csrf::FIELD_NAME, "confirm", "ids"];