t

forms

FormControllerBase

trait FormControllerBase extends HasValues with HasTouches with HasErrors

A component to manage data editing lifecycle. Supply the initial values and optionally track fine-grained changes. Very few assumptions are made in this base class leaving the details to subclasses. A react context is provided for child components, if desired.

The form can be used as controlled or uncontrolled. Provide a "value" parameter to ake it controlled. Controlled is a better model if you have components (such as a reset button) outside the form's structure that can alter the value being edited.

To do

Remove dependency on Future. Make general F or use js.Promise.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FormControllerBase
  2. HasErrors
  3. HasTouches
  4. HasValues
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. sealed trait Action extends AnyRef

    Actions that are sent by child form elements.

  2. case class Context(props: FormProps, initialValue: Value, validate: UndefOr[FormValidator]) extends Product with Serializable

    The context is slightly duplicative in that initialValues and validate are already in FormProps.

  3. case class FieldErrors(errors: Errors, merge: Boolean) extends Action with Product with Serializable

    Set field errors.

    Set field errors. Either replacing all of the existing or merging this into the existing field errors.

  4. case class FieldValue(field: String, value: Value, validate: Boolean) extends Action with Product with Serializable

    Send the attibute that changed and an updated Value object.

  5. case class FormActions(setFieldValue: (String, Value, Boolean) => Unit = (_, _, _) => (), setError: (String, String) => Unit = (_, _) => (), setErrors: (Errors, Boolean) => Unit = (_, _) => (), setTouched: (String, Boolean) => Unit = (_, _) => (), submit: () => Unit = () => (), reset: (Option[Value]) => Unit = _ => (), validateField: (String) => Future[Errors] = _ => Future.successful(EmptyErrors), validateForm: (Value) => Future[Errors] = _ => Future.successful(EmptyErrors)) extends Product with Serializable

    API to change this this component's state, church encoding of Actions.

    API to change this this component's state, church encoding of Actions. Most of these send state changing messages to the reducer. This API is should be easier to use then sending raw Action messages.

  6. case class FormHandlers(handleChange: (String, Value) => Unit = (_, _) => (), handleBlur: (String) => Unit = _ => (), handleSubmit: react.vdom.FormEventHandler[Form] = _ => (), handleReset: react.vdom.FormEventHandler[Form] = _ => ()) extends Product with Serializable

    Handlers for controls.

    Handlers for controls. These are close to what's needed for most html controls.

  7. case class FormProps(isValid: Boolean, dirty: Boolean, values: Value, errors: Errors, touched: Touches, isValidating: Boolean, isSubmitting: Boolean, submitCount: Int, didMount: Boolean, handlers: FormHandlers, actions: FormActions, initialValue: Value) extends Product with Serializable

    Props passed to the child component.

  8. type FormValidator = (Value, Seq[String]) => Future[Errors]

    Validate values, only checking Seq[String] fields, or all fields (form level validation) if Nil.

    Validate values, only checking Seq[String] fields, or all fields (form level validation) if Nil. Return errors.

  9. trait Props extends Object with PropsBase
    Annotations
    @JSType()
  10. trait PropsBase extends Object
    Annotations
    @JSType()
  11. trait PropsInit extends Object with PropsBase
    Annotations
    @JSType()
  12. case class Reset(values: Value) extends Action with Product with Serializable

    Reset using the values provided including initialValues.

  13. type ResetCallback = (Value, FormActions) => Future[Unit]
  14. case class State(value: Value, postAction: Option[Action] = None, submitting: Boolean = false, validating: Boolean = false, resetting: Boolean = false, errors: Errors = EmptyErrors, touched: Touches = EmptyTouches) extends Product with Serializable
  15. type SubmitCallback = (Value, FormActions) => Future[Unit]
  16. case class Submitting(f: Boolean) extends Action with Product with Serializable

    Submit the form.

    Submit the form.

    f

    Whether submission should start or if it has ended.

  17. case class Touched(field: String, validate: Boolean) extends Action with Product with Serializable

    Touch a field potentially forcing validation.

  18. case class Validating(f: Boolean, errors: Option[Errors]) extends Action with Product with Serializable

    Indicate whether we are validating, performed asynchronously.

    Indicate whether we are validating, performed asynchronously. This action does not perform validation itself, it just provides the status or the result of validation if f = false.

    f

    validating status "is or is not validating"

    errors

    validation errors from the validation ffort, if any

  19. type Validator = (Option[Any]) => Future[String]

    Validate a single value, return user message.

    Validate a single value, return user message. Used for field level validations.

  20. type Validators = Dictionary[Validator]

    Validators indexed by attribute name.

Abstract Value Members

  1. abstract val Name: String
  2. abstract val _errors: Service
    Definition Classes
    HasErrors
  3. abstract val _touches: Service
    Definition Classes
    HasTouches
  4. abstract val _values: Service
    Definition Classes
    HasValues

Concrete Value Members

  1. val EmptyValidators: Dictionary[Validator]
  2. val FormContext: ReactContext[Context]
  3. def apply(props: PropsInit)(children: (FormProps) => ReactNode): ReactNode
  4. def handleReset(currentValue: Value, dispatch: Dispatch[Action], initialValue: MutableRef[Value], factions: FormActions, reset: UndefOr[ResetCallback]): react.vdom.FormEventHandler[Form]
  5. def handleSubmit(dispatch: Dispatch[Action]): react.vdom.FormEventHandler[Form]
  6. def makeFormActions(currentValue: Value, dispatch: Dispatch[Action], initialValue: MutableRef[Value], validate: UndefOr[FormValidator]): FormActions
  7. def makeFormHandlers(currentValue: Value, dispatch: Dispatch[Action], initialValue: MutableRef[Value], factions: FormActions, reset: UndefOr[ResetCallback]): FormHandlers
  8. val render: (Props) => ReactNode
  9. def resetForm(dispatch: Dispatch[Action], initialValue: MutableRef[Value], nextValues: Option[Value]): Unit
  10. def runFieldLevelValidations(validators: Dictionary[Validator], values: Value): Future[Errors]

    Dummy for now.

    Dummy for now. Always return EmptyErrors.

  11. def runValidations(values: Value, fieldLevelValidators: Dictionary[Validator], handler: UndefOr[FormValidator]): Future[Errors]

    Run validation handlers.

    Run validation handlers. Merge resulting errors. Maybe the return value should be Future[Option[Errors]]. If the validators fail, return the exception in the Future's error channel.

    TODO: Keep all errors by using an applicative non-empty list.

  12. def setError(dispatch: Dispatch[Action], field: String, message: String): Unit