A simple form builder for Go.
- Simple form definition
- Form validation
- Form rendering (currently fyne only)
- Display conditions for form fields
- Many form field types
Look at the example directory for a simple example.
You can run the example with go run example/example.go.
The base field type that all other fields inherit from. DO NOT USE DIRECTLY.
Properties:
Id(string): Unique identifier for the field.DisplayCondition(string): Condition for displaying the field. If the condition is not met, the field will not be displayed.Validators([]Validator): List of validators for the field.Value(string): Value of the field.form(*Form): Reference to the form that the field belongs to.error(error): Error message for the field if validation fails.
Available display conditions
AlwaysDisplay: Always display the field.CustomDisplayCondition: Custom display condition. Takes a function with the propfield anythat returns a boolean as theCondition.IsValidDisplayCondition: Display the field if the fields given inFieldIdsare valid.IsInvalidDisplayCondition: Display the field if the fields given inFieldIdsare invalid.AllFieldsValidDisplayCondition: Display the field if all fields in the form are valid.HasValueDisplayCondition: Display the field if the field with the givenFieldIdhas the givenValue.DisplayAfter: Display the field after the field with the givenFieldIdis visible and valid (entry finished).OrDisplayCondition: Display the field if any of the givenConditionsare met.AndDisplayCondition: Display the field if all the givenConditionsare met.
Available validators
CustomValidator: Custom validator. Takes a function with the propfield anythat returns (bool, error) as theValidator.AllFieldsVaild: Validate the field if all fields in the form are valid.IsValidValidator: Validate the field if the fields given inFieldIdsare valid.
A simple message field that can be used to display text. No user input is possible.
A simple text input field.
Properties:
Placeholder(string): Placeholder text for the input field.Prompt(string): Prompt text for the input field.
Available validators
NotEmptyValidator: Validate that the field is not empty.MinLengthValidator: Validate that the field has aMinLengthnumber of characters.MaxLengthValidator: Validate that the field has aMaxLengthnumber of characters.IpValidator: Validate that the field is a valid IPv4 address.RegexValidator: Validate that the field matches the givenRegexPattern(string).UrlValidator: Validate that the field is a valid URL. (matches the regex^https?://.)
A number input field that only accepts numbers.
Available validators
MinValidator: Validate that the field is greater than or equal toMin.MaxValidator: Validate that the field is less than or equal toMax.IsIntegerValidator: Validate that the field is an integer.
A multiple choice field that allows the user to select one option from a list.
Properties:
Options(map[string]Option): List of options to choose from.
Option has the following properties:
Label(string): Label for the option.Description(string): Description for the option.
Available validators
ChoiceValidator: Validate that the field is one of the options inOptions.
A group of fields that can be displayed conditionally.
Properties:
Fields([]Field): List of fields in the group.heading(string): Heading for the group.
- Add more field types
- Add way to customize error messages (e.g., for translations)
- Add more UI frameworks for rendering (e.g., charm.sh for terminal UIs)
- Add more display conditions
- Add more validators
- Add tests
- Add more examples
- Clen up code
- Add more documentation