I have a form which needs to generate its fields dynamically. The fields will be of two type: text or dropdown. The text part is working fine but I'm having issues with the dropdown. I can't seem to set the valuesProvider
of the field. Here's the code:
const DataFormEditorType = require('nativescript-ui-dataform').DataFormEditorType;
exports.onLoaded = function(args) {
var page = args.object;
var productVM = Observable({
id: 1
});
page.bindingContext = productVM;
dataForm = page.getViewById("myDataForm");
let configForm = {};
var name = 'Dropdown'; //loaded dynamically
configForm[name] = ''; //add field to list of fields with empty initial value
productVM.set('config', configForm);
console.log(dataForm); //return RadDataForm
var temp = dataForm.getPropertyByName('Dropdown');
console.log(temp); //returns null
var pickerEditor = new PropertyEditor();
pickerEditor.type = DataFormEditorType.Picker;
temp.editor = pickerEditor;
temp.valuesProvider = 'Test 1, Test 2'; //will be loaded dynamically
}
XML
<df:RadDataForm id="myDataForm" source="{{ config }}" />
I'm trying to follow this example but I guess it doesn't translate into JS exactly.
Edit:
I've managed to get to the property. The problem was spaces in the names of fields. After converting all names to camelcase, I', getting a value in temp
variable but still no success on the valuesProvider. I've tried
temp.valuesProvider = 'Test 1, Test 2';
temp.valuesProvider = ['Test 1, Test 2'];
temp.valuesProvider = ['Test 1', 'Test 2'];
None of these work.