Ask the assistant
0/400
Your question is processed by an AI service and kept to improve answers. Do not enter personal data.

    Form

    A form: collects the values of its TextFormField fields, checks their #validators rules and reports a successful submit. Field values go into @ variables declared on the form itself: the field name:"email" writes to @email .

    Type: single-child

    Form @email:""
      Column spacing:12
        TextFormField name:"email"
          #decoration labelText:"Email"
        FilledButton onPressed:"form:submit"
          Text "Send"

    Parameters

    Parameter Type Default Description
    @name:value variable — A form field. The name matches the name: of a field inside; the value is the initial one. After a successful submit the variable holds the entered value (an empty field gives an empty value)

    The form has no other parameters: every @ variable on Form is one of its fields.

    Form actions

    The form is driven by string actions that any element inside it sends — usually a button's onPressed:"…" :

    Action What it does
    form:submit Checks all fields. If any one fails, shows the messages and stops. Otherwise writes the field values into the form's @ variables and sends form:submit further out
    form:save:<name>:<value> Writes the value into the variable of field <name> without checking
    form:clear:<name> Clears the variable of field <name>

    What happens after a submit. A successful submit goes out as the form:submit action. You can catch it on the screen with an Actions "form:submit":{…} element around the form; without one the action goes to the host app. Without a handler, success can only be seen from the changed @ variables — and on the screen it looks as if nothing happened.

    The validation rules ( #isEmpty , #email , #minLength , #match …) are described in TextFormField .

    Examples

    Sign-in with a submit handler

    @sent:false
    Actions "form:submit":{sent = true}
      Form @email:"" @password:""
        Column spacing:12
          TextFormField name:"email"
            #decoration labelText:"Email"
            #validators
              #isEmpty "Enter your email"
              #email "Invalid address"
          TextFormField name:"password" obscureText:true
            #decoration labelText:"Password"
            #validators
              #isEmpty "Enter your password"
              #minLength 8 "At least eight characters"
          FilledButton onPressed:"form:submit"
            Text "Sign in"
          Text {sent ? "Sent" : ""}

    Password confirmation

    #match compares the field with another field of the same form:

    Form @password:"" @confirm:""
      Column spacing:12
        TextFormField name:"password" obscureText:true
          #decoration labelText:"Password"
          #validators
            #minLength 8 "At least eight characters"
        TextFormField name:"confirm" obscureText:true
          #decoration labelText:"Once more"
          #validators
            #match "password" "Passwords do not match"
        FilledButton onPressed:"form:submit"
          Text "Save"

    Clearing a field with a button

    Form @promo:""
      Row spacing:8
        Expanded
          TextFormField name:"promo"
            #decoration labelText:"Promo code"
        TextButton onPressed:"form:clear:promo"
          Text "Reset"

    AutofillGroup

    Declares the fields of one form as one account that the device fills in and saves as a whole. A password manager fills in not the password field but the "login + password" pair: #autofillHints on a field says what it holds, and AutofillGroup ties the fields together — without it the platform sees the fields one by one and can neither offer the pair nor ask whether to save it.

    It wraps whatever holds the fields (not each field): the fields can sit inside layouts, macros and conditions.

    Type: wrapper

    @email:""
    @password:""
    AutofillGroup
      Column spacing:12
        TextField value:$email textInputAction:next
          #autofillHints "username"
        TextField value:$password obscureText:true textInputAction:done
          #autofillHints "password"
    Parameter Type Default Description
    onDisposeAction string commit What to do with the input when the group leaves the screen: commit — offer to save it, cancel — forget it. cancel is for a form where saving is wrong: someone else's data, a one-off check

    On iOS the group also removes the keyboard flicker when moving between a regular field and a password field: the system does not recreate the fields of the current autofill group, and the form switches fields just like a native one.

    Without a child the element draws nothing.

    Differences between the app and the site

    • Form on the site is a <form> : the #validators rules are checked on form:submit with the same rules and the same messages, and the Actions "form:submit" handler is called. form:save:… and form:clear:… change the field's value on the page.
    • On the site, after a submit the field values are not written into the form's @ variables : the text {email} stays the same after the submit. To get the value as it is typed on the site, use value:$variable on the field (see TextFormField ).
    • AutofillGroup on the site draws only its child: in the browser the fields are tied together by the autocomplete attribute, which the fields already get from #autofillHints .

    See also