Skip to content

Giving array to the model to feed an ArrayInput doesn't work.

Summary

Hi,

Seems like filling model with Array doesn't fill the input Array Input.

Steps to reproduce

I'm trying to make a form where a user can comeback and always see the fields as he let it last time he came. In order to do that I'm filling the model bind with my formSchema with data saved in backend.

                var that = this;

                $.each(datas, function (key, data) {
                    that.model[data.inputName] = that.convertValueForFront(data.inputValue, data.inputType);
                });

convertValueForFront is just use to correctly cast to array or boolean.

            convertValueForFront(value, type) {
                if (type === "array") {
                    return JSON.parse(value);
                } else if (type === "boolean") {
                    return Boolean(value);
                } else {
                    return value;
                }
            },

the schema that i'm using is the same than in the documentation

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "arrayInput": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}

What is the current bug behavior?

When I fill the array input by myself (with browser and keyboard) and log the model I can see that the model have n Array with each elem inside. It's updating itself correctly.

When I try to fill the model by inserting the same kind of array in it, my form is just like the default one.

What is the expected correct behavior?

The ArrayInput should take the array from inside de model and generate itself n input with each element of the array inside the input.

Thanks