Archived
generated from mitchell/rust_template
add validation builder
This commit is contained in:
+7
-7
@@ -11,11 +11,11 @@ use web_sys::FormData;
|
||||
///
|
||||
/// This can be useful to use the same validation logic on the front
|
||||
/// end and backend without duplicating the logic.
|
||||
pub struct Validator<FD> {
|
||||
pub struct FormValidator<FD> {
|
||||
pub(crate) validations: Vec<Rc<dyn ValidationFn<FD>>>,
|
||||
}
|
||||
|
||||
impl<FD: FormToolData> Validator<FD> {
|
||||
impl<FD: FormToolData> FormValidator<FD> {
|
||||
/// Validates the given form data.
|
||||
///
|
||||
/// This runs all the validation functions for all the fields
|
||||
@@ -40,8 +40,8 @@ pub struct Form<FD: FormToolData> {
|
||||
|
||||
impl<FD: FormToolData> Form<FD> {
|
||||
/// Gets the [`Validator`] for this form.
|
||||
pub fn validator(self) -> Validator<FD> {
|
||||
Validator {
|
||||
pub fn validator(self) -> FormValidator<FD> {
|
||||
FormValidator {
|
||||
validations: self.validations,
|
||||
}
|
||||
}
|
||||
@@ -57,10 +57,10 @@ impl<FD: FormToolData> Form<FD> {
|
||||
}
|
||||
|
||||
/// Splits this [`Form`] into it's parts.
|
||||
pub fn to_parts(self) -> (RwSignal<FD>, Validator<FD>, View) {
|
||||
pub fn to_parts(self) -> (RwSignal<FD>, FormValidator<FD>, View) {
|
||||
(
|
||||
self.fd,
|
||||
Validator {
|
||||
FormValidator {
|
||||
validations: self.validations,
|
||||
},
|
||||
self.view,
|
||||
@@ -131,7 +131,7 @@ pub trait FormToolData: Default + Clone + 'static {
|
||||
///
|
||||
/// However, the code to render the views are not configured out, it
|
||||
/// simply doesn't run, so the view needs to compile even on the server.
|
||||
fn get_validator() -> Validator<Self> {
|
||||
fn get_validator() -> FormValidator<Self> {
|
||||
let builder = FormBuilder::new(Self::default(), Self::Style::default());
|
||||
let builder = Self::build_form(builder);
|
||||
builder.validator()
|
||||
|
||||
Reference in New Issue
Block a user