add onselect event for view field
In response to Alain Fontaine & Fred Christmas wish (https://forum.ninox.com/t/h7hbkmp?r=h7hbvzj), I have added a viewEvent function to Ninext project.
Just put viewEvent at true in an init code formula:
var configLoadModules := {
completion: true,
badges: true,
evalJS: true,
viewEvent: true
};
html(http("GET", "https://raw.githubusercontent.com/JacquesTur/Ninext/main/loadModules.html").result);
This will be returned:
All that remains is to add the onselect() event function to the view field source formula:
The full code of the view field is :
function onselect(selectedID : text) do
'Selected customer' := first(select Customer where ID = selectedID)
end;
select Customer
When you select a line in the field of view, the onselect function is called instead of the automatic event that displays a popup.
selectID represents the full (alphanumeric) id of the selected record. The context record this remains the owner record of the view field.
The second part (select Customer) is the standard initialization for the field of view content.
61 replies
-
I hate to say this but you have to stop doing Ninox’s work for them. Unless they pay you.
-
I can't seem to get it to work. I got the module loaded
and I put this in the formula of my view:
function onselect(selectedID : text) do Nr := first(select Table3 where Id = selectedID) end; select Table3
I'm in Table1. Nr is a text field in Table1.
When I select a record in the view element it opens the record.
What am I missing?
-
I don't understand why it doesn't work for you! I have tried on the online app and on the Mac and everything works. Can you try with the test application attached?
-
Jacques, your DB worked fine. Just to verify that I'm using the MacOS app. I've attached my test DB. It is a mess so:
1) open the System table to load your modules
2) open Table1, select record 1, then scroll down to the view element
3) I've changed the view formula to link a Table3 reference field like you did for your sample but the view still opens the record and not link the field.
Thanks for helping out.
Sean , yeah probably something my wee brain can't yet grasp.
-
Jacques TUR Just brilliant. Where there is a many to many join I have always wanted to be able to popup the record of the other side, not the join. Solved!
In a Student --< Join >-- Course relationship, this pops up the record of the student from the course
function onselect(selectedID : text) do let a := first(select Join where Id = selectedID); popupRecord(a.Student) end; select Join
Regards John
-
I have just added the ability to update the view field when the record or some fields changes.
Just add an onload() function in "Display field only, if:" :
function onload() do 'selected Customer'.ID end; true
The function must return the alphanumeric ID of the record to be selected hot from the view field.
note: the constant 'true' after the function ensures that the field will be displayed.In this example, when the value of the 'selected customer' field changes, the selection of the view field is updated automatically.
-
Sei un grande Jacques TUR
Content aside
-
4
Likes
- 3 mths agoLast active
- 61Replies
- 1672Views
-
16
Following