onRecordEditStop - Runs on ANY Click?

Hi Folks

Perhaps this is expected behaviour but I find it odd.

If I have a call on onRecordEditStop, whenever I simply click on a record body (not only a DP or label) the call is made - as if I had edited something on the form.

Tried saveData before hand - but no difference? Any feedback welcome.

OnRecordEditStop runs when a field has focus and the user clicks on the form background or a label so that no editable field is focused anymore.

ngervasi:
OnRecordEditStop runs when a field has focus and the user clicks on the form background or a label so that no editable field is focused anymore.

Thanks for the clarity Nicola - that seems a bit illogical though, does it not?

I had anticipated that the function would run IF a field on the form had been edited and not yet saved. Yet when I do a saveData() so all editing is finished and complete, there should be no call to onRecordEditStop?

In this particular instance, I run a calculation and the calc sets a checkbox to true, then I run databaseManager.saveData() and all seems well. BUT if I then click anywhere on the form the onRecordEditStop function is fired? I had been using that function to uncheck that box when data was edited, so each individual column did not need to be read for editing, but that’s useless in this instance if it fires on just selecting the record?

I think it’s correct: onRecordEditStart is triggered when the user focuses a field for data enter and onRecordEditStop is triggered when the user removes the focus from editable fields. If the user moves between fields using the tab key or clicking the second event is not triggered.
The editing stop event is not depending on the user actually changing some values, if you need to check that you can use the onDataChange at field level or the databaseManager.getEditedRecords() before saving to the backend or even table events.

ngervasi:
I think it’s correct: onRecordEditStart is triggered when the user focuses a field for data enter and onRecordEditStop is triggered when the user removes the focus from editable fields. If the user moves between fields using the tab key or clicking the second event is not triggered.
The editing stop event is not depending on the user actually changing some values, if you need to check that you can use the onDataChange at field level or the databaseManager.getEditedRecords() before saving to the backend or even table events.

Nicola, editing a record does not actually start when the user clicks in an editable field.
They might just click here and there and not edit anything.
But onRecordEditStart() has already executed!

I’m facing the problem of identifying the moment the user starts typing (that is, editing) to enable/disable ‘Save’ and ‘Cancel’ and some other buttons on our navigation panel.
And I find it a bit wrong to switch button on/off at the point when the user clicks in a field: they will be puzzled as to whether they changed anything on the record or not.
In addition, it would be annoying for them if I enable ‘Save’ and ‘Cancel’ every time onRecordEditStart() regardless of actual changes in data, they’d have to do more clicks and users don’t like it.

Is there any way to accomplish this?
Servoyans’ input would be highly appreciated.

Cheers,
Maria

Please share some thoughts on the topic.
I won’t abandon hope :)

I tend to agree with the ‘onRecordEditxxx’ events behaving a bit odd.
What exactly do they add to the ‘onElementFocusxxx’ events if the ‘onRecordEditxxx’ events are being triggered as soon as the user enter/leave a field?

I would also assume ‘onRecordEditxxx’ events being triggered when a real change has been done, more like an automatic databaseManager.hasRecordChanges() function.

Could anyone of Servoy comment on this?

maria:
Is there any way to accomplish this?

@maria: Speaking about this last function > if you combine ‘onRecordEditStop’ with the databaseManager.hasRecordChanges() function, I thing you can very well determine whether or not to show the save button…

mboegem:
I tend to agree with the ‘onRecordEditxxx’ events behaving a bit odd.
What exactly do they add to the ‘onElementFocusxxx’ events if the ‘onRecordEditxxx’ events are being triggered as soon as the user enter/leave a field?

The difference is that as long as the users keep the focus inside editable fields (by tabbing or clicking) the onRecordEditStop is not fired.
Those two events are very old and made perfect sense when there was no way of disabling AutoSave. Basically it mimics the Filemaker behavior.
For example: you could get a lock on the record as soon as the user click the first editable field and keep that lock while it enters data in multiple fields until the user triggers the onRecordEditStop by clicking the form background, then you could do you checks, save the data and release the lock.
Personally I don’t use this anymore in new solutions, I do prefer to have forms fields not editable until the user clicks the Edit button and I prefer to perform all the checks when he clicks the Save or Cancel buttons but in some old solutions I still use those events.
Changing those events behavior would break a lot of old solutions.

mboegem:
I tend to agree with the ‘onRecordEditxxx’ events behaving a bit odd.
What exactly do they add to the ‘onElementFocusxxx’ events if the ‘onRecordEditxxx’ events are being triggered as soon as the user enter/leave a field?

I would also assume ‘onRecordEditxxx’ events being triggered when a real change has been done, more like an automatic databaseManager.hasRecordChanges() function.

Could anyone of Servoy comment on this?

maria:
Is there any way to accomplish this?

@maria: Speaking about this last function > if you combine ‘onRecordEditStop’ with the databaseManager.hasRecordChanges() function, I thing you can very well determine whether or not to show the save button…

Marc, this is exactly what I did.
There is a small problem with it.
If the user clicks in the field and does nothing then I should trigger onRecordEditStop event (by returning false in onRecordEditStart).
If I don’t - then onRecordEditStart will not be triggered again when the user starts typing, and changes in the record will not be recognised (they won’t even be listened to).
However, if I do return false in onRecordEditStart - that moves the focus out of the field - no way to edit the field at all.

How do you deal with this?

ngervasi:

mboegem:
I tend to agree with the ‘onRecordEditxxx’ events behaving a bit odd.
What exactly do they add to the ‘onElementFocusxxx’ events if the ‘onRecordEditxxx’ events are being triggered as soon as the user enter/leave a field?

The difference is that as long as the users keep the focus inside editable fields (by tabbing or clicking) the onRecordEditStop is not fired.
Those two events are very old and made perfect sense when there was no way of disabling AutoSave. Basically it mimics the Filemaker behavior.
For example: you could get a lock on the record as soon as the user click the first editable field and keep that lock while it enters data in multiple fields until the user triggers the onRecordEditStop by clicking the form background, then you could do you checks, save the data and release the lock.
Personally I don’t use this anymore in new solutions, I do prefer to have forms fields not editable until the user clicks the Edit button and I prefer to perform all the checks when he clicks the Save or Cancel buttons but in some old solutions I still use those events.
Changing those events behavior would break a lot of old solutions.

We have two Visual FoxPro developers here and we are in fact moving a FoxPro application to Servoy.
Well, that’s how the FoxPro application behaves: it only changes the status of save/cancel and other toolbar buttons when actual changes to data have been made.
FoxPro has this InteractiveChange method/event that they use to implement it.

Would it be possible to introduce some kind of a similar method/event in Servoy if the current onRecordEditStart cannot be changed?
I do believe there are many Servoy developers out there who would like to switch save/cancel buttons status when the user types rather than clicks in the field.
By the way, it’s what a lot of commercial applications do, including Servoy :wink: The save button is only activated after we make chages in the form code or design.

Cheers,
Maria

onRecordEditStart and editStop is just that you are entering edit mode… Its always been this way (like nicola also explained, can be used for locking and so on)
For example you see the “e” appearing in the status bar of the smart client.

What you want is a form level ondatachange i guess, make a feature request for that.

maria:
I do believe there are many Servoy developers out there who would like to switch save/cancel buttons status when the user types rather than clicks in the field.
By the way, it’s what a lot of commercial applications do, including Servoy :wink: The save button is only activated after we make chages in the form code or design.

Hi Maria,

didn’t had the chance to reply to your earlier question, but this works for me:

function onRecordEditStop(record, event)
{
	elements.btn_save.enabled = databaseManager.hasRecordChanges(record);
	return true;
}

This is the only thing that should be assigned to make a toggle of a save button work…

Hope this helps

jcompagner:
onRecordEditStart and editStop is just that you are entering edit mode… Its always been this way (like nicola also explained, can be used for locking and so on)
For example you see the “e” appearing in the status bar of the smart client.

What you want is a form level ondatachange i guess, make a feature request for that.

Will do.
Thanks Johan.

mboegem:

maria:
I do believe there are many Servoy developers out there who would like to switch save/cancel buttons status when the user types rather than clicks in the field.
By the way, it’s what a lot of commercial applications do, including Servoy :wink: The save button is only activated after we make chages in the form code or design.

Hi Maria,

didn’t had the chance to reply to your earlier question, but this works for me:

function onRecordEditStop(record, event)

{
elements.btn_save.enabled = databaseManager.hasRecordChanges(record);
return true;
}




This is the only thing that should be assigned to make a toggle of a save button work...

Hope this helps

Correct me if I’m wrong, Marc, but onRecordEditStop will run after I tab out of the field.
Before I tab out I might type in something and wish to save or cancel without tabbing out (users won’t know they’d have to tab out to enable/disable buttons).
So I’m trying to do my logic in onRecordEditStart rather than xxxStop.

I hope it makes sense for not only myself :lol:

Cheers,
Maria

maria:
Correct me if I’m wrong, Marc, but onRecordEditStop will run after I tab out of the field.
Before I tab out I might type in something and wish to save or cancel without tabbing out (users won’t know they’d have to tab out to enable/disable buttons).
So I’m trying to do my logic in onRecordEditStart rather than xxxStop.

I hope it makes sense for not only myself :lol:

Each event will have its own behaviour and moment that it will be triggered, so maybe it’s not just the xxxStop you want, but also the xxxStart… but also this combination can still result in disabled button (think of editing in a field in just tab nowhere)
Also a global (form) onDataChange won’t help, as onDataChange will fire only when you leave a field (or tab on to another field)…

I think you’ll need a good scheme of what needs to happen when & where. Based on that you have to experiment with - probably - a combination of events to reach your goal.

By just adding a simple line to the code I posted, you’ll have the record returned and you can check if there are any changes in each event, so that shouldn’t be a stopper as well.

mboegem:
Each event will have its own behaviour and moment that it will be triggered, so maybe it’s not just the xxxStop you want, but also the xxxStart… but also this combination can still result in disabled button (think of editing in a field in just tab nowhere)
Also a global (form) onDataChange won’t help, as onDataChange will fire only when you leave a field (or tab on to another field)…

I think you’ll need a good scheme of what needs to happen when & where. Based on that you have to experiment with - probably - a combination of events to reach your goal.

By just adding a simple line to the code I posted, you’ll have the record returned and you can check if there are any changes in each event, so that shouldn’t be a stopper as well.

Ok, thanks Marc.

ngervasi:
OnRecordEditStop runs when a field has focus and the user clicks on the form background or a label so that no editable field is focused anymore.

Somehow it doesn’t always work.
I trigger onRecordEditStart() when I click in the field. Then I type something and click my ‘Cancel’ button which is supposed to trigger onRecordEditStop().
But it does not.
I run databaseManager.rollbackEditedRecords() in the button method and I thought rollbacking would trigger onRecordEditStop, too. It doesn’t though, is it supposed to?

Cheers,
Maria

rollbackEditedREcords() will not trigger a onRecordEditStop as far as i can see.
Only saveData() will do that

Make a case if this is behavior that you want/need.

jcompagner:
rollbackEditedREcords() will not trigger a onRecordEditStop as far as i can see.
Only saveData() will do that

Make a case if this is behavior that you want/need.

I will, thanks Johan.

Another question please.
How come when I edit a field and then click on a button to save or cancel (on another form) - and the focus stays in the field after I clicked on the button?
See, I click in a field → onRecordEditStart fires → my buttons toolbar changes its view to make ‘save’ and ‘cancel’ visible → type text → click ‘save’ → type again right away while the focus is in the field → onRecordEditStart is not fired. Apparently, it should not fire because the focus never left the field and/or entered another field.
But why does it not leave the field?

P.S. I set up test methods on the field and see that onFocusLost is not fired when I click my ‘cancel’ button.
onFocusLost is called when I click ‘save’ but again in a weird way: first my save() method is called and when it comes to a certain point (at that point it calls a global method from another module) only then onFocusLost is fired. Isn’t this really weird?
The buttons are JLabel beans by the way, not Servoy normal buttons. They have mouse listeners on them to capture mouseIn, mouseOut and mouseClicked and call appropriate methods on those events.
Is anyone able to explain what’s happening?

Cheers,
Maria

so you use labels that act as buttons?
then it is logical because labels don’t get the focus. So the focus stays in the field.
But if you say in that action: databasemanager.saveData() and that return true.
then the focus should get out of the field.
If that is not the case then make a case for this.