I'm trying to create a form with an array of objects. The form functions in my browser, however, when I submit the data I am unable to process the args because the submitted names are not properly enumerated.
I've created a simplified case to illustrate.
Given this schema:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"enum": ["internal", "external"]
},
"url": {
"type": "string",
"format": "uri"
}
}
}
}
And these options:
{
"stickyToolbar": true,
"renderForm": true,
"fields": {
"item": {
"fields": {
"type": {
"label": "Type",
"optionLabels": ["Internal", "External"]
},
"url": {
"label": "URL"
}
}
}
},
"form": {
"attributes": {
"action": "save",
"method": "post",
"enctype": "multipart/form-data"
},
"buttons": {
"submit": {}
}
}
}
When I use Firebug to inspect the names of items as they are added, every item is named the same either: name=""_0_type" or name="_0_url". This is the case regardless how many items I add.
If I submit the form with 10 items, then I'll receive 10 args named "_0_url" and 10 args named "_0_type". I can save the data but I lose the order information and have know idea which type values are associated with which url since the args are submitted in arbitrary order.
I have found that if I leave the options field bits out like this:
{
"stickyToolbar": true,
"renderForm": true,
"form": {
"attributes": {
"action": "save",
"method": "post",
"enctype": "multipart/form-data"
},
"buttons": {
"submit": {}
}
}
}
then the fields are enumerated properly.
Unfortunately, I lose the formatting bits for my form. Some things I can move into the schema; however, in my real world case I am using a file field and that requires a string type in the schema and a file type in the options. So I must have a fields definition in the options to use a file type in my object items array.
I tried to debug this in alpaca.js.
My guess is the problem is related to the addItem: function(index, fieldOptions, value, insertAfterId) found near line 7108 of the non-minimized alpaca.js file. On line 7116 the parent options are being retrieved in order to be passed on to the new item:
if (fieldOptions == null && _this.options && _this.options.fields && _this.options.fields["item"]) {
fieldOptions = _this.options.fields["item"];
}
Perhaps the index in fieldOptions.name must be assigned the index value pass to addItem?
Unfortunately, the solution might be trickier than that because later in render: function(view, callback) defined on line 3564 we find the following comment at line 3572:
// last try to see if we can populate the label from propertyId
It appears the subfield names are already defined and hence copied because on line 3577 a check is performed: if (!this.options.name). If the subfield name was not being used then going in here would create a new id; unfortunately this is not the case.
Anyway, I'm a big fan of Alpaca and think it's great, but I really need a resolution to this problem. Perhaps I'm just doing something wrong in my schema/options decls.
I appreciate any advice or effort to investigate and address this issue.
Thanks!
-- Bob