{"id":24302904,"url":"https://github.com/digipolitan/roadblock","last_synced_at":"2025-03-06T14:26:58.346Z","repository":{"id":62452969,"uuid":"108096741","full_name":"Digipolitan/roadblock","owner":"Digipolitan","description":null,"archived":false,"fork":false,"pushed_at":"2018-12-13T17:25:19.000Z","size":60,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-17T04:46:14.845Z","etag":null,"topics":["form","swift","validation"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Digipolitan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-24T08:12:00.000Z","updated_at":"2018-12-13T17:25:11.000Z","dependencies_parsed_at":"2022-11-01T23:46:39.637Z","dependency_job_id":null,"html_url":"https://github.com/Digipolitan/roadblock","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Froadblock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Froadblock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Froadblock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Froadblock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Digipolitan","download_url":"https://codeload.github.com/Digipolitan/roadblock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242225916,"owners_count":20092673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form","swift","validation"],"created_at":"2025-01-17T00:20:01.781Z","updated_at":"2025-03-06T14:26:58.325Z","avatar_url":"https://github.com/Digipolitan.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"Roadblock\n=================================\n\n[![Swift Version](https://img.shields.io/badge/swift-4.2-orange.svg?style=flat)](https://developer.apple.com/swift/)\n[![Build Status](https://travis-ci.org/Digipolitan/roadblock.svg?branch=master)](https://travis-ci.org/Digipolitan/roadblock)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Roadblock.svg)](https://img.shields.io/cocoapods/v/Roadblock.svg)\n[![Carthage Compatible](https://img.shields.io/badge/carthage-compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Platform](https://img.shields.io/cocoapods/p/Roadblock.svg?style=flat)](http://cocoadocs.org/docsets/Roadblock)\n[![Twitter](https://img.shields.io/badge/twitter-@Digipolitan-blue.svg?style=flat)](http://twitter.com/Digipolitan)\n\nRoadblock, a simple way to check forms verifications.\n\n## Installation\n\n### CocoaPods\n\nTo install Roadblock with CocoaPods, add the following lines to your `Podfile`.\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '9.0'\nuse_frameworks!\n\npod 'Roadblock'\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate Roadblock into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```\ngithub 'Digipolitan/roadblock' ~\u003e 1.0\n```\n\nRun `carthage update` to build the framework and drag the built `Roadblock.framework` into your Xcode project.\n\n## The Basics\n\nFirst to catch errors you need to add the following keys to your **Localizable.string** file\n\n```strings\n\"errors.validator.required\" = \"Missing required field\";\n\"errors.validator.email\" = \"Invalid email\";\n\"errors.validator.min_length\" = \"Minimum %1$d characters\";\n\"errors.validator.max_length\" = \"Maximum de %1$d characters\";\n```\n\nAfter that, you need to implement the `FormDelegate` protocol\n\n```swift\nextension ViewController: FormDelegate {\n\n    func formDidSubmit(_ form: Form) {\n        self.validateButtonClicked()\n    }\n}\n```\n\nThen you can register the form on your `viewDidLoad()` method like following\n\n```swift\n@IBOutlet weak var emailTextField: UITextField!\n@IBOutlet weak var passwordTextField: UITextField!\npublic var form: Form!\nprivate var formTextFieldChainable: FormTextFieldDelegateChainable?\n\noverride func viewDidLoad() {\n    super.viewDidLoad()\n\n       self.form = Form(fields: [\n           .init(identifier: Fields.email,\n                 target: self.emailTextField,\n                 name: \"email\",\n                 validator: FieldValidators.group(FieldValidators.required(), FieldValidators.email()),\n                 transformer: FieldTransformers.group(FieldTransformers.trim(), FieldTransformers.emptyIsNil())),\n           .init(identifier: Fields.password,\n                 target: self.passwordTextField,\n                 name: \"password\",\n                 validator: FieldValidators.group(FieldValidators.required()),\n                 transformer: FieldTransformers.group(FieldTransformers.trim(), FieldTransformers.emptyIsNil()))\n           ], delegate: self)\n\n       let formTextFieldChainable = FormTextFieldDelegateChainable(form: self.form)\n       self.emailTextField.delegate = formTextFieldChainable\n       self.passwordTextField.delegate = formTextFieldChainable\n       self.formTextFieldChainable = formTextFieldChainable\n   }\n}\n```\n\nThen you can handle the forms errors on youre `@IBAction` function\n\n```swift\n@IBAction func validateButtonClicked() {\n    self.view.endEditing(true)\n    do {\n        try self.form.validate()\n    } catch {\n        if let err = error as? FormError {\n            let alertController = UIAlertController(title: \"Error\", message:\n                    err.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)\n            alertController.addAction(UIAlertAction(title: \"Dismiss\",style: UIAlertActionStyle.default, handler: nil))\n\n            self.present(alertController, animated: true, completion: nil)\n        }\n    }\n    return\n}\n```\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for more details!\n\nThis project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md).\nBy participating, you are expected to uphold this code. Please report\nunacceptable behavior to [contact@digipolitan.com](mailto:contact@digipolitan.com).\n\n## License\n\nRoadblock is licensed under the [BSD 3-Clause license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigipolitan%2Froadblock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigipolitan%2Froadblock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigipolitan%2Froadblock/lists"}