Eureka: Form data validation

Created on 23 Oct 2015  路  24Comments  路  Source: xmartlabs/Eureka

Hi, is there any way of validating the data of the rows like the validations in XLForm?

It would be nice to e.g. only activate a specific ButtonRow if the whole form is valid and this depends upon the validations of each row (e.g. row 1,2 and 3 must not be empty)

Validations discussion feature request

Most helpful comment

any updates on this?

All 24 comments

Yes! Please add form validation from XLForm! High priority for my team before we are able to make the switch

Yes please. This is the only reason I haven't switched from XLForm.

It would be very useful if Eureka had automatic validation for numbers, phone numbers, email, ..., Custom validation function for fields and ability to display validation error in each field.

  • 1

Hi guys. Thanks for Eureka!

  • 1!
    It would be very cool !

馃憤

+1

+1

+1

+1

+1!!

+2

+1

In the meantime, please follow/contribute to this SO question

Thanks to you! - from newbie's like me

i was using SwiftValidator for validate text field for each cell.

I've been using SwiftValidate in the following way...

set up my validator chain and a property to hold the last calculated valid state:

  var formValid = false
  var validationIterator: ValidationIterator!

  func configureValidation() {
    validationIterator = ValidationIterator() {
      $0.resultForUnknownKeys = true
      $0.registerChain(ValidatorChain() {
        $0.stopOnException = true
        $0.stopOnFirstError = true
        }
        <~~ ValidatorRequired()
        <~~ ValidatorStrLen() {
          $0.minLength = 2
        }
        , forKeys: [Row.FirstName, Row.LastName]
      )
    }
  }

Validate after form initialization and after each row value change. You can also use the formValid state as a row condition:

      <<< NameRow(Row.LastName) {
        $0.title = "Last name"
        $0.value = lastName
        }.onChange { [weak self] _ in
          self?.validate()
      }

      <<< ButtonRow(Row.Submit) {
        $0.title = "Save"
        $0.disabled = Condition.Function([], { (form) -> Bool in
          return !self.formValid
        })
        $0.onCellSelection { cell, _ in
          self.submitPressed()
        }
      }

validate like this:

  func validate() {
    formValid = validationIterator.validate(form.values())
    submitRow?.evaluateDisabled()
    navigationItem.rightBarButtonItem?.enabled = formValid
    // Display the error somewhere
  }

Hi @shanmarkus, can you show an example of how are you using SwiftValidator. Thanks.

Hello @Opelor I've just committed a first working version of Eureka SwiftValidator TextRow:

https://github.com/demetrio812/EurekaSwiftValidatorComponents

Let me know and feel free to suggest improvements.

Cheers,
Dem

Hi @demetrio812! I've just tested the example and it's a great start!

The first suggestion is to have the ability to customize the validation messages ("This field is required", "Must be a valid email address"..etc.). The main reason being translation.

Great Contribution!!

Hello @Opelor ,
that's already supported by SwiftValidator:

$0.rules = [RequiredRule(message: "My custom message")]

You can also create your own rules.

Let's avoid spamming here though, please write any other suggestion on the project page.

Thanks,
Dem

My team is also depending on this Feature to be able to migrate. We were using Validator on normal fields (https://github.com/adamwaite/Validator)

any updates on this?

Finally we implemented build-in validations feature in Eureka 2.0.0-beta.1 version, Notice that this version only works on swift3. Take a look at the readme and example project for more info about how to use it.
Any feedback is welcome.

Regards

Awesome, thanks! I'm currently migrating to the 2.0.0-beta.1 and will let you know if I find anything worth to mention

Was this page helpful?
0 / 5 - 0 ratings