Skip to main content

FormSetFactory

Struct FormSetFactory 

Source
pub struct FormSetFactory { /* private fields */ }
Expand description

Factory for creating FormSets dynamically

This allows you to create FormSets with different configurations without defining them statically.

Implementations§

Source§

impl FormSetFactory

Source

pub fn new(prefix: String) -> Self

Create a new FormSetFactory

§Examples
use reinhardt_forms::FormSetFactory;

let factory = FormSetFactory::new("form".to_string());
assert_eq!(factory.extra(), 1);
Source

pub fn with_extra(self, extra: usize) -> Self

Set extra forms count

§Examples
use reinhardt_forms::FormSetFactory;

let factory = FormSetFactory::new("form".to_string())
    .with_extra(3);
assert_eq!(factory.extra(), 3);
Source

pub fn with_can_delete(self, can_delete: bool) -> Self

Enable deletion

§Examples
use reinhardt_forms::FormSetFactory;

let factory = FormSetFactory::new("form".to_string())
    .with_can_delete(true);
assert!(factory.can_delete());
Source

pub fn with_can_order(self, can_order: bool) -> Self

Enable ordering

§Examples
use reinhardt_forms::FormSetFactory;

let factory = FormSetFactory::new("form".to_string())
    .with_can_order(true);
assert!(factory.can_order());
Source

pub fn with_max_num(self, max_num: Option<usize>) -> Self

Set maximum number of forms

§Examples
use reinhardt_forms::FormSetFactory;

let factory = FormSetFactory::new("form".to_string())
    .with_max_num(Some(10));
assert_eq!(factory.max_num(), Some(10));
Source

pub fn with_min_num(self, min_num: usize) -> Self

Set minimum number of forms

§Examples
use reinhardt_forms::FormSetFactory;

let factory = FormSetFactory::new("form".to_string())
    .with_min_num(2);
assert_eq!(factory.min_num(), 2);
Source

pub fn extra(&self) -> usize

Get extra forms count

Source

pub fn can_delete(&self) -> bool

Check if deletion is enabled

Source

pub fn can_order(&self) -> bool

Check if ordering is enabled

Source

pub fn max_num(&self) -> Option<usize>

Get maximum number of forms

Source

pub fn min_num(&self) -> usize

Get minimum number of forms

Source

pub fn create(&self) -> FormSet

Create a FormSet from this factory

§Examples
use reinhardt_forms::{FormSetFactory, FormSet};

let factory = FormSetFactory::new("form".to_string())
    .with_extra(3)
    .with_can_delete(true);

let formset = factory.create();
assert_eq!(formset.prefix(), "form");
assert!(formset.can_delete());
Source

pub fn create_model_formset<T: FormModel>(&self) -> ModelFormSet<T>

Create a ModelFormSet from this factory

§Examples
use reinhardt_forms::FormSetFactory;

let factory = FormSetFactory::new("user".to_string())
    .with_extra(2);

let formset = factory.create_model_formset::<User>();

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.