Hi all,
Thanks to Igor's and Dean's help I was able to get a basic JSON
defined form working [1].
data = { "contacts": { "name": "A", "type": "phone"}, ... }
but I would like to be able to work with an array for that matter like
data = { "contacts": [{ "name": "A", "type": "phone"}, {"name":
"B", "type": "email"}], ... }
As a angularjs newbie it looks like using the ng:repeat would lead
into the right direction, but introducing it in the following widget
(on the level of subfieldset) didn't work out, so what would the
proper approach then?
angular.widget('my:form', function(element) {
this.descend(true);
this.directives(true);
return function(element) {
var scope = this,
schema = scope.$eval(element.attr('schema')),
model = element.attr('data'),
fieldset = angular.element('<fieldset></fieldset>');
angular.forEach(schema, function processField(field) {
var name = this.model + '.' +
field.name,
fieldElStr;
// has hierarchical subforms?
if (field.children) {
var subfieldset = angular.element('<fieldset></
fieldset>');
var legend = angular.element('<legend>' +
field.name +
'</legend>');
subfieldset.append(legend);
var addButton = angular.element('<a href=""
ng:click="' + model + '.'+
field.name + '.$add()">add</a>');
subfieldset.append(addButton);
angular.forEach(field.children, processField, {model:
name, curDOMParent: subfieldset});
fieldset.append(subfieldset);
return;
}
// on to the field display...
Thanks,
Niko
[1]
http://groups.google.com/group/angular/browse_thread/thread/7fc29b2ed4ff32ab/a99dd409fd4cc4d0