koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
546 stars 155 forks source link

x-rules validation isn't working for array of objects #133

Closed MaxSPRTL closed 4 years ago

MaxSPRTL commented 4 years ago

Hello there !

I've a little issue here. It seems that I can't write my own validation functions for array of objects...

The "test" function in options.rules is well called when the main property attach to it is a simple type as a String or a Number. It works as well with an array of simple types (not each time an element is added but only at validation). But when it comes an array of objects with "oneOf" property. The "test" function is not called.

const model = {}

const options =  {
    hideReadOnly: true,
  rules: {
    test: function(e){
      console.log(e)
      return 'test'
    }
  }
}

const schema = {
    type: 'object',
    properties: {
        objectArrayProp: {
            type: 'array',
            items: {
                type: 'object',
                oneOf: [
                    {
                        title: 'Object1',
                        properties: {
                            objectType: {
                                type: 'string',
                                const: 'object1',
                                title: 'Sub object type'
                            },
                            dateProp: {
                                type: 'string',
                                format: 'date',
                                title: 'I\'m a date'
                            }
                        }
                    },
                    {
                        title: 'Object2',
                        properties: {
                            objectType: {
                                type: 'string',
                                const: 'object2'
                            },
                            colorProp: {
                                type: 'string',
                                format: 'hexcolor',
                                title: 'I\'m a color'
                            }
                        }
                    }
                ]
            },
      'x-rules': [
        'test'
      ]
        }
    }
}

Vue.component('VJsf', VJsf.default)

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: {
    model,
    options,
    schema,
    valid: null
  }
});
albanm commented 4 years ago

The new release 1.12 should fix this. Feel free to reopen the issue if necessary.

MaxSPRTL commented 4 years ago

Hi @albanm, thanks for the fix! I'll check as soon as possible ;)