Hi, I’m working on a small project where the employee’s geo-location, i.e., the latitude and longitude fields should be auto-filled by clicking the “Generate Geo-location” button.
I’ve used javascript in the Java controller to fetch coords data from the browser to the respective fields but when I press “OK”, the values are not saved, leading to an instance created but without the geo-location data.
It depends on how you did that. If your JavaScript code only puts text directly into vaadin frontend, then Jmix component value may not be updated. Did you use .setValue method in your code?
Another thing to try that comes to my mind, is to update the edited entity field with its setter, something like myAttendLog.setLocationLatitude() .
I see.
You are executing JavaScript code, and that is running inside the browser, on the client side.
JavaScript doesn’t have access to saveToDatabase() because it’s on the server side.
You need to provide a way to communicate between those 2 layers.
One way is to have a REST endpoint that JavaScript can call. If you go that way, be sure to set CORS properly.
Another way would be to make your own component, e.g. geoCoordinates, by integrating text field and whatever is getting you the navigator.geolocation.getCurrentPosition().