I'm experimenting with the NPM forms module. it can be viewed here
I can't figure out how to bind values to the fields generated. i.e. how to preset the field content with existing values that I load from a json file.
Could someone familiar with this module please tell me how to set the value displayed in the widget when the form is displayed?
Annotated code below:
/* configObject is an object parsed from json I load from a file
each itemElement below contains: { "value": <a string>, "type": <a string - 'integer', 'float', 'string', or 'boolean'>, "length": <an integer> } i.e. fieldName1: { "value": "contentOfFieldName1", "type": "string", "length": 12 }*/
_.each(configObject, function (itemElement, itemIndex) { if (['integer', 'float'].indexOf(itemElement['type']) >=0) { fieldType = 'number' } else { fieldType = itemElement['type']; } /* At this point, itemElement.value = the value I want to insert as the visible value of the form field. How do I do this? I've tried newField.bind(itemElement.value); -----------------------------------------------------------------------------------------------------*/ var newField = fields[fieldType]({required: true}); //newField.bind(itemElement.value); // no error but nothing happens formObject[itemIndex] = newField; //formObject[itemIndex].bind(itemElement.value); // no error but nothing happens //formObject.bind({itemIndex: itemElement.value}); // error: formObject has no method 'bind' });