These are chat archives for canjs/canjs

28th
May 2016
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 28 2016 10:57
@Macrofig no problem I did make it work
Juan Orozco
@Macrofig
May 28 2016 16:46
@web-mech This works for me. I seem to remember define needing a default value for a setter to call (haven't verified this, will do so later).
var selection = {
    type: 'number',
    value: 0
};

var Test = can.Map.extend({
    define: {
        0: {
            Type: can.Map,
            Value: Object
        },
        1: {
            Type: can.Map.extend({
                define: {
                    selection: selection,
                    date: {
                        type: 'string',
                        validate: {
                            required: function () {
                                console.log('this',this);
                                return this.attr('selection') === 1;
                            }
                        },
                        value: ''
                    }
                }
            }),
            Value: Object
        }
    }
});

var test = new Test({});
test[1].attr('selection', 1);

console.assert(typeof test[1].attr('errors.date') !== 'undefined', "Validation properly fired");
console.assert(typeof test.attr('1').attr('errors.date') !== 'undefined', "Can also access via attr");