خرید بک لینک

Vote count: 0

I created a Memory store (model) based on a simple Json Schema like this and tried to put an an invalid value, however the object was still created inside the store.

<script>

    require(
        [
        'dojo/_base/declare',
        'dstore/Memory',
        'dmodel/extensions/jsonSchema'
        ], 
    function (declare, Memory, jsonSchema) {
        var myStore = new Memory({

            model: jsonSchema({
                properties: {
                    someProperty: {
                        type: "number",
                        minimum: 0,
                        maximum: 10
                    },
                }
            })
        });

        myStore.put({ id: 1, someProperty: -21 });

    });
</script>

Next I tried to use the String Validator like this

<script>

    require(
        [
        'dojo/_base/declare',
        'dstore/Memory',
        'dmodel/extensions/jsonSchema',
        'dmodel/validators/StringValidator'
        ], 
    function (declare, Memory, jsonSchema, StringValidator) {
        var myStore = new Memory({

            model: jsonSchema({
                properties: {
                    someProperty: new StringValidator({
                        // must be at least 4 characters
                        minimumLength: 4,
                        // and max of 20 characters
                        maximumLength: 20,
                        // and only letters or numbers
                        patte: /^w+$/
                    }),
                }
            })
        });

        myStore.put({ id: 1, someProperty: '#' });

    });
</script>

Again the property was created in the store. There were no validation errors. Am I doing something wrong?

My end goal is to build a model from json schema, then when data is entered into the model, to validate based on the constraints defined in the schema. Data that does not match the constraints should not be put into the store. Is this even possible?

asked 12 secs ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 8 تير 1395 ساعت: 21:17

صفحه بندی