json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

How to Trigger a validation error on a field that is in an nested array. #839

Closed raquintero closed 7 years ago

raquintero commented 7 years ago

Hello, I have a regex pattern on a field, with my custom validation message that works fine normally.

"fieldA": {
       "type": "object",
       "properties": {
        "_value": {
        "type": "string",
        "title": "Field A",
         "pattern": "^(4[0-8][0-5]|[0-9]|[0-9][0-9]|[0-3][0-9][0-9])$",
          "validationMessage": "Valid Range is [0 - {Field B ÷ 2 - 15}]"
           }
      }
}

The key for this field is parentA.parentB.parentC.parentD[].fieldA However, if the value for fieldB changes, the acceptable range of values for fieldA needs to change, so basically, I want to know how to "trigger" this validation message on the form, if it is inside of an array? From the controller I am trying: scope.$broadcast('schemaForm.error.parentA.parentB.parentC.parentD[].fieldA','tv4-202',false); I've tried all combinations, nothing works.

Anthropic commented 7 years ago

@raquintero I've done similar by changing the options in the form based on conditions. But it depends on how many different values B has as to how well that would work for you. Have a look at the calculate plugin I added to the examples int he alpha, you may find you can validate against a hidden field instead and calculate its value from field B.

Anthropic commented 7 years ago

Please re-open if you do not feel the question has been answered sufficiently, I'm spring cleaning quiet issues.