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
-
Hello everyone,
I made an update with two additions: V1.05 : 12/05/2022
- if onclick return true, the default event is fire. In this case, if line is newly selected, the default popup appear
- add targetColumnCaption on event parameter of onclick event
The example below changes the selection of a record each time the user clicks on the column named "selected". If the user clicks on another column then the default event (Ninox's) is executed, which causes the Fields form to pop up.
function onclick(event : any) do if event.targetColumnCaption = "selected" then var field := first(select Fields where ID = event.targetID); field.(selected := not selected); false else true end end; var current := this; select Fields where Tables.Configurations = current
-
After using this function, I noticed a flaw. When a row is already selected and you click on a column different from "selected", nothing happens, the popup does not open because the row was already selected.
To change this, just :
- that the onclick function systematically returns false,
- add yourself the popupRecord function to open the form when you want.function onclick(event : any) do var selCustomer := first(select Customer where ID = event.targetID); if event.targetColumnCaption = "selected" then selCustomer.(checked := not checked) else popupRecord(selCustomer) end; false end; select Customer
With these modifications, the behavior of the list is identical to a normal list if you click
-
Just trying to use the 'onclick' event to popup the other parent record rather than just show the child (that was clicked in the list). It does work, but when viewing that parent, the record selection controls (arrows) are all disabled and the arrow keys do not work as they normally do when a record is 'popped up' from a list. So once the parent record has 'popped up', there is no way to select the next/previous child and view its other parent, apart from closing that popup and clicking the next/previous one in the list.
Is there any way this can be changed so that one can move up and down the list of children and display the other parent as specified in the onclick function?
-
I've been using this extension with no problems for at least a month now, but today it has started to behave differently. I have a dashboard that shows all the registered students in classes for the teacher that is logged in. Clicking on a student with the extension allowed the student record to pop up without popping up the registration record. Today, the registration table pops up first. When I close it, the student pop up remains. So it seems to be popping both up at the same time. Any ideas why this is happening and how to fix it?
-
Jacques TUR Hello Jacques, great stuff you made with your Ninext "Extensions". I really appreciate that. The fieldInspector saved me many hours of seaching.
Now I tried the viewEvent Tool. I also - like many here - have a student-join-course relationship of 3 tables.
I have a view which select the student table. I see the students name in one column. Every student has 4 oor 5 courses. So I have for each course a column. I like to click in the column-field of the student to open the right join database entry.
Is this possible with your extension?
Maurice
-
Hello,
This is a message for those who use function onselect with view fields.
Because of Ninox version 3.8 I had to remove the onselect function. However, onclick still works and it does more than onselect: https://forum.ninox.com/t/60hbvbz?r=h7hdy3jIf you have any problems adapting your code, please let me know and I will help you.
I am using an example sent to me to show how to switch from onselect to onclick
function onselect(selectedID : text) do let q := first(select Registration where Id = selectedID); popupRecord(q.Students); true end;
With onclick, it becomes:
function onclick(event : any) do let q := first(select Registration where Id = target.ID); popupRecord(q.Students); true end;
if you want to go further and create more complex mechanisms, here are the variables available to you in the event parameter:
event : { previousID, targetID, targetLineNum, targetColumnNum, targetColumnValue, targetColumnCaption }
For example, you could open the q.Students popup only when column 2 is clicked :
function onclick(event : any) do if event.targerColumnNum = 2 then let q := first(select Registration where Id = target.ID); popupRecord(q.Students); true; else "// default behaviour of the view field" false; end; end;
-
Hi all -
Here is my setup. I have a dashboard, "All Horses Stats" that has a view element to a table called DashTemp. In DashTemp is a number field called HorseID.
Now I want to click on a record in the view element but onclick to a table called Horses but use the data in HorseID in DashTemp to match a similar field in Horses. I can't use recordId as there is no relationship between the tables.
I've tried:
function onclick(event : any) do var selHorse := first(select Horses where HorseID = event.targetId.HorseID); popupRecord(selHorse); true end;
and
function onclick(event : any) do var selHorse := first(select Horses where HorseID = event.HorseID); popupRecord(selHorse); true end;
Is there a way to access other field's data from the event. part or can do I only have access to the recordId?
Thanks,
Content aside
-
4
Likes
- 1 mth agoLast active
- 61Replies
- 1657Views
-
16
Following