Page 1 of 1

dataproviderID setting to null

PostPosted: Tue Nov 27, 2012 5:58 pm
by Harjo
HI,

I have some method where I scan all the elements of a form and get the dataproviderID of an element.

Code: Select all
var vProviderID = forms[vForm].elements[vElem].getDataProviderID()


Now for example this code returns vProviderID as a string: "scopes.globals.filter_monthfilter"
How do I set this global now to null?

Re: dataproviderID setting to null

PostPosted: Wed Nov 28, 2012 3:02 pm
by Joas
Try something like:
Code: Select all
   if (/^scopes\./.test(vProviderID)) {
      var split = vProviderID.split(".");
      scopes[split[1]][split[2]] = null;
   }

You probably need to do some more checks, but you get the idea.

Re: dataproviderID setting to null

PostPosted: Wed Nov 28, 2012 3:14 pm
by Harjo
yes I did something like that already, but we still have code run in Servoy 6 and Servoy 6.1
In Servoy 6 there is 'scopes.' in front, so I wanted to make this just work on both...

But you say, that is not possible?

Re: dataproviderID setting to null

PostPosted: Wed Nov 28, 2012 4:17 pm
by Joas
So you want the same code to work in 6.0 and 6.1? That doesn't look like a good idea to me, but it is possible if you do something like:
Code: Select all
   var split = vProviderID.split(".");
   if (/^globals\./test(vProviderID)) {
      globals[split[1]] = null;
   } else if (/^scopes\./.test(vProviderID)) {
      scopes[split[1]][split[2]] = null;
   }

Re: dataproviderID setting to null

PostPosted: Wed Nov 28, 2012 6:19 pm
by Harjo
No, but i thought there was maybe another way to set a (global) dataprovider independant of the name.

Re: dataproviderID setting to null

PostPosted: Wed Nov 28, 2012 6:33 pm
by jbrancoIF
this should work:
Code: Select all
eval(vProviderID + '=null;')


or if you have a form
Code: Select all
vForm.controller.setDataProviderValue(vProviderID, null)

Re: dataproviderID setting to null

PostPosted: Wed Nov 28, 2012 6:45 pm
by Joas
Harjo wrote:No, but i thought there was maybe another way to set a (global) dataprovider independant of the name.

Hmmm, I'm don't think I understand correctly what you are trying to do.

Re: dataproviderID setting to null

PostPosted: Wed Nov 28, 2012 9:59 pm
by Harjo
jbrancoIF wrote:this should work:
Code: Select all
eval(vProviderID + '=null;')


or if you have a form
Code: Select all
vForm.controller.setDataProviderValue(vProviderID, null)


YES jBrancoIF, you are the man!

Code: Select all
vForm.controller.setDataProviderValue(vProviderID, null)

works perfectly. and despite of the name is 'scopes.globals.myglobal' (6.1.x) or 'globals.myglobal' (6.0.x)

Thanks!