NyFormData class

Base class for defining form structure, data, and behavior in Nylo applications.

NyFormData provides the internal form logic engine used by NyFormWidget. It manages field initialization, validation, data extraction, and state updates.

Users should extend NyFormWidget directly rather than subclassing this.

Constructors

NyFormData(String name)
Creates a new form data instance with the specified name.

Properties

getLoadData → dynamic Function()?
Returns the data loading function for async form initialization.
no setter
hashCode int
The hash code for this object.
no setterinherited
init → dynamic Function()?
Override this method to provide initial form data.
no setter
isReady Stream<bool>
Stream for the form
no setter
name String?
The unique name identifier for this form.
getter/setter pair
onChanged ↔ dynamic Function(Field field, dynamic value)?
Callback function invoked when any field value changes.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateName String
Returns the state management key for this form.
no setter
updated StreamController?
Stream controller for broadcasting form updates and changes.
no setter
widgets List
Returns the list of form widgets and child elements.
no setter

Methods

clear() → void
Clear the form
clearField(String key) → void
Clear a field in the form
data({String? key}) → dynamic
Returns the data for the form If a key is provided, it will return the data for that key
dispose() → void
Dispose of the form resources
errorBag() List<FormValidationError>
Get the error bag for the form
extractCurrentValues() Map<String, dynamic>
Extracts current values from all fields for preservation during refresh. Returns a Map with snake_case keys and field values.
fieldData(Field field) Map<String, dynamic>
Get the data for a field
fields() List
Override this method to define the structure of your form.
findField(String key) Field
Find a field in the form by its key
formReady() → void
Check if the form is ready
getFields(StreamController stream) List
Processes and configures form fields for state management.
initFields() → void
Initialize the form fields and apply any pending initial data.
initialData(dynamic loadData()) → void
Load data for the form
initializeStream() StreamController?
Initialize the stream for the form
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onChange(String field, Map<String, dynamic> data) → void
On change function for the form
refreshFields() → void
Refreshes form fields by re-calling fields() while preserving existing values. Called during hot reload to pick up field definition changes.
setData(Map<String, dynamic> data, {bool refreshState = true}) → void
Set the data for the form.
setDataFromInit() → dynamic
Loads and applies initial data from the init function to form fields.
setFieldOptions(String key, FormCollection options) → void
Set the options for a field in the form.
setFieldValue(String key, dynamic value) → void
Set the value for a field in the form If the field does not exist, it will throw an exception
submit({required dynamic onSuccess(dynamic value), dynamic onFailure(List<FormValidationError> errors)?, bool showToastError = true}) → void
Submit the form If the form is valid, it will call the onSuccess function
toString() String
A string representation of this object.
inherited
updateField(String key, Field update(Field item)) → void
Update a field in the form
validate({dynamic onSuccess(Map<String, dynamic> formData)?, dynamic onError(List<FormValidationError> errors)?}) bool
Check if the form passes validation
valueChange(dynamic data, {dynamic onChanged()?}) → dynamic

Operators

operator ==(Object other) bool
The equality operator.
inherited