1

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.

Whip
  • 1,891
  • 22
  • 43
  • You will have to set type to Picker, please share the complete code you are using. – Manoj Feb 17 '20 at 17:31
  • I added the missing code. Though I'm not using it anymore, I'm using metadata to set up the form but I'd like to know why it didn't work. I also tried an isolated case with a boolean value and trying to change it from checkbox to switch (no valuesProvider) but it doesn't change. – Whip Feb 18 '20 at 06:02
  • The code is not complete, I'm not sure how you are injecting the new property to dataform. It's easier if you can share a Playground example. – Manoj Feb 18 '20 at 07:06
  • I'm sorry I don't have the code anymore. How would you 'inject the new property to dataform'? – Whip Feb 18 '20 at 12:25

0 Answers0