onDataChange when changing record listview or tableview

I have a problem with field validation on a tableview in a tabpanel.

The goal is if the user enters null (by deleting the contents of the field), the field will automatically get a value of 0 via onDataChange event.

The field is already pre-populated with zero but it does happen that a user enters a valid, say 12, changes his mind and deletes the value (leaving null in the field).

I’ve attached to the follwing method to all the fields/columns onDataChange event:

var newValue = arguments[1];

if (newValue == null){
	var fld = application.getMethodTriggerElementName();
	var frm = application.getMethodTriggerFormName();
	var dpID = forms[frm].elements[fld].getDataProviderID();
	
	// if the user clicked on an other record on the list
	// we will have a problem here
	// because we will be setting the value on the same column,
	// but not on the same record!
	// this is because the currentIndex has, naturally, changed!
	controller.setDataProviderValue(dpID, 0);
}

with the problems expressed in the code.

Of course I can just return false from the onDataChange event, not allowing the user to leave the field. And its what I’m using now. Although I rather use the default value functionality.

Anybody has a way to solve this?
If not I think a great addition to the onDataChange event would be that it would call the assigned method with and extra argument the index of the record that fired the event!

Best,
Miguel

I do not see your problem.
The ondatachange event and the action triggered by it are
executed on the same record.

I tryed the following onDataChange method on

if(arguments[1] == null)
{
<dataprovider>=0
}

when i set the value of the in record 1 to Null and then click on record 3,the value of the in record 1 is set to 0, not the in record 3

Regards,

Hans

Or to stay close to your code :

var fld = application.getMethodTriggerElementName(); 
var frm = application.getMethodTriggerFormName(); 

if(arguments[1] == null)
{
forms[frm][fld]=0
}

so do not use controller.setDataProviderValue

Hans Nieuwenhuis:
Or to stay close to your code :

var fld = application.getMethodTriggerElementName(); 

var frm = application.getMethodTriggerFormName();

if(arguments[1] == null)
{
forms[frm][fld]=0
}




so do not use controller.setDataProviderValue

I’ve been playing with the problem in the mean while.
And, although I also prefer the less verbose syntax, the problem is definitively another.
Servoy completly looses the reference to the fieldName and returns null from

var fld = application.getMethodTriggerElementName();

The docs do mention that it’s possible that application.getMethodTriggerElementName() returns null. Inspite of this I think that in this context the reference should be present.

So in my opinion this seems like a true bug.

best,
Miguel

Sorry, not exact copy of your code.
Below is correct code :

var fld = application.getMethodTriggerElementName(); 
var frm = application.getMethodTriggerFormName(); 
var dpID = forms[frm].elements[fld].getDataProviderID();

if(arguments[1] == null)
{
forms[frm][dpID]=0
}

You can completly ignore my last post :oops:

The reason why some calls to application.getMethodTriggerElementName() return null was because I failed to name some of those elements :oops:

Now that I cleaned that up, the real problem was easier to find!

Both codes work fine and it shouldn’t really matter if one uses:
“First Syntax”

forms[frm][dpID] = 0

Or, alternatively:
“Second Syntax”

currentcontroller.setDataProviderValue(dpID, 0);

But unfortunately this is only true for form level methods. For global methods only the first syntax works well, the second syntax fails silently.

best,
Miguel

Hi,

There is no difference if the method is global or not.
This works fine for eather syntax.

The difference is the fact that your form is on a tabpanel.

If you use currentController, it returns the base form.

So if the field you are testing is on form which is displayed
in a tabpanel on the currentcontroller wil point to .

Regards

Hans Nieuwenhuis:
Hi,

There is no difference if the method is global or not.
This works fine for eather syntax.

The difference is the fact that your form is on a tabpanel.

If you use currentController, it returns the base form.

So if the field you are testing is on form which is displayed
in a tabpanel on the currentcontroller wil point to .

Regards

Txs for pointing that out to me.
I would assume that currentcontroller would be defined to the controller of the current running method and not the current main form (which seems odd to me, but certain things are just framework design).

Txs again for putting me on the right track.

best,
Miguel