Matterway
    Preparing search index...

    Function toggleField

    • Toggle field component for boolean input. Supports both static and dynamic props based on current state.

      Parameters

      • props: UiToggleFieldProps

        Configuration object

        • name

          Name of the field used for state management

        • label

          Label text or a function that receives params with data and value, returning a promise of label

        • required

          True or false or a function that receives params with data and value, returning a promise of boolean

        • disabled

          True or false or a function that receives params with data and value, returning a promise of boolean

        • invalid

          True or false or a function that receives params with data and value, returning a promise of boolean or string

        • hidden

          True or false or a function that receives params with data and value, returning a promise of boolean

      Returns Element

      Basic usage with required props

      toggleField({
      name: 'notifications',
      label: 'Enable notifications',
      });

      Usage with async props depending on other fields

      toggleField({
      name: 'autoSave',
      label: async ({data}) => `Auto-save (${data.userType})`,
      disabled: async ({data}) => data.userType === 'guest',
      });

      Usage with conditional visibility and validation based on field value

      toggleField({
      name: 'darkMode',
      label: 'Dark Mode',
      hidden: ({data}) => !data.supportsDarkMode,
      invalid: async ({value}) => !value ? 'Please enable dark mode' : false,
      });