https://github.com/feathersui/feathersui-validators
A port of the form validation classes from Apache Flex (formerly Adobe Flex) to Feathers UI for Haxe and OpenFL
https://github.com/feathersui/feathersui-validators
adobe-flex apache-flex feathers-ui form-validation form-validator haxe openfl
Last synced: about 2 months ago
JSON representation
A port of the form validation classes from Apache Flex (formerly Adobe Flex) to Feathers UI for Haxe and OpenFL
- Host: GitHub
- URL: https://github.com/feathersui/feathersui-validators
- Owner: feathersui
- License: apache-2.0
- Created: 2022-08-15T18:07:48.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T22:21:20.000Z (8 months ago)
- Last Synced: 2025-01-22T17:28:37.747Z (3 months ago)
- Topics: adobe-flex, apache-flex, feathers-ui, form-validation, form-validator, haxe, openfl
- Language: Haxe
- Homepage: https://api.feathersui.com/validators/
- Size: 267 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Validators for Feathers UI
A port of the form validation classes from [Apache Flex](https://flex.apache.org/) (formerly Adobe Flex) to [Feathers UI](https://feathersui.com/) for [Haxe](https://haxe.org/) and [OpenFL](https://openfl.org/).
Includes the following validators:
- [`CreditCardValidator`](https://api.feathersui.com/validators/current/feathers/validators/CreditCardValidator.html)
- [`CurrencyValidator`](https://api.feathersui.com/validators/current/feathers/validators/CurrencyValidator.html)
- [`DateValidator`](https://api.feathersui.com/validators/current/feathers/validators/DateValidator.html)
- [`EmailValidator`](https://api.feathersui.com/validators/current/feathers/validators/EmailValidator.html)
- [`NumberValidator`](https://api.feathersui.com/validators/current/feathers/validators/NumberValidator.html)
- [`PhoneNumberValidator`](https://api.feathersui.com/validators/current/feathers/validators/PhoneNumberValidator.html)
- [`RegExpValidator`](https://api.feathersui.com/validators/current/feathers/validators/RegExpValidator.html)
- [`SocialSecurityValidator`](https://api.feathersui.com/validators/current/feathers/validators/SocialSecurityValidator.html)
- [`StringValidator`](https://api.feathersui.com/validators/current/feathers/validators/StringValidator.html)
- [`ZipCodeValidator`](https://api.feathersui.com/validators/current/feathers/validators/ZipCodeValidator.html)## Minimum Requirements
- Haxe 4.0
- OpenFL 8.9.7## Installation
Run the following command in a terminal to install [feathersui-validators](https://lib.haxe.org/p/feathersui-validators) from Haxelib.
```sh
haxelib install feathersui-validators
```## Project Configuration
After installing the library above, add it to your OpenFL _project.xml_ file:
```xml
```
## Usage
The following example validates a text input when it loses focus:
```haxe
var textInput = new TextInput();
addChild(textInput);var validator = new NumberValidator();
validator.source = textInput;
validator.valueFunction = () -> textInput.text;
validator.triggerEvent = FocusEvent.FOCUS_OUT;
validator.addEventListener(ValidationResultEvent.VALID, event -> {
textInput.errorString = null;
});
validator.addEventListener(ValidationResultEvent.INVALID, event -> {
var errorString = "";
for (validationResult in event.results) {
if (!validationResult.isError) {
continue;
}
if (errorString.length > 0) {
errorString += "\n";
}
errorString += validationResult.errorMessage;
}
textInput.errorString = errorString;
});
```The following example validates a form when it is submitted:
```haxe
var form = new Form();
addChild(form);var textInput = new TextInput();
var formItem = new FormItem("My Field", textInput);
form.addChild(formItem);var submitButton = new Button("Submit");
form.addChild(submitButton);
form.submitButton = submitButton;var validator = new NumberValidator();
validator.source = null;
validator.valueFunction = () -> textInput.text;
// don't trigger automatically
// we'll do it manually when the form is submitted
validator.triggerEvent = null;
validator.addEventListener(ValidationResultEvent.VALID, event -> {
textInput.errorString = null;
});
validator.addEventListener(ValidationResultEvent.INVALID, event -> {
var errorString = "";
for (validationResult in event.results) {
if (!validationResult.isError) {
continue;
}
if (errorString.length > 0) {
errorString += "\n";
}
errorString += validationResult.errorMessage;
}
textInput.errorString = errorString;
});form.addEventListener(FormEvent.SUBMIT, event -> {
var hasErrors = false;
var validators:Array = [validator];
var events = Validator.validateAll(validators);
for (event in events) {
for (validationResult in event.results) {
if (validationResult.isError) {
hasErrors = true;
break;
}
}
if (hasErrors) {
break;
}
}
if (hasErrors) {
// some checks were invalid, so don't submit
return;
}// everything is valid, so now it can be sent to the server
// using URLLoader or something
});
```## Documentation
- [feathersui-validators API Reference](https://api.feathersui.com/validators/)