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!
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.
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).