This question already has answers here:
How to detect click/touch events on UI and GameObjects
(4 answers)
Closed 5 years ago.
I have a system that creates buttons based on the files in a directory. I need to call a function in a script based on what a child object of the button's Text component text property reads. Basically, i need to modify each button to call a function with a specific paramter. How would I do this?
I think you need to check this : Event trigger Script
https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html
The Event Trigger Script allow you to call a method of child component on trigger (click, mouseover..).
(check this : http://answers.unity3d.com/questions/974622/unity-502f1-ui-button-onclick-function.html)
EDIT :
If you do not know in advance which method is to be assigned:
you can use System.Reflection to retrieve the associated method.
string name = "BtnAction";
MethodInfo m = t.GetMethod(name);
I hope this will help you :
For each button, attach the components "Event Trigger" and your script with all your methods.
Then use reflection to get the associated method.
Finally, set the Event Trigger component using :
button.onClick.AddListener (FunctionToCall);
Related
Using c++ builder borland (bcb6).
I wish to invoke manually button click event. I did:
FMap->bbDoneInClick(NULL);
While Done button located on the FMap form, but something went wrong with that.
Do I need to call bbDoneInClick with different parameters and not with NULL ?
Instead of NULL use the Form1 or the bbDone itself ...
it depends on the event code itself how it uses the Sender parameter
Also you can call the event handler safely only if the form is already created
if it does not access Canvas you can use it even in TForm1::TForm1 constructor
if it does you need to take care of not using it prior to OnShow or OnActivate
to avoid VCL problems or App crashes
for common handlers it is sufficient to use main window ... (I use this instead of NULL)
if you have single even handler for multiple components then the even is usually deciding the operation or target from the Sender parameter so in that case you need to pass the pointer to component itself
I've been trying to implement what's been asked in this Stack Overflow question, here:
Calculation for status in Archer GRC based on date
Trying to create a status field based on a number of Value Lists that
users select from, but a request has been made that we check a date
field for a value to ensure an estimated date has been set so that the
calculation can determine if the status of the record is "In
Progress", "Late" or "Not Started".
...and now, I have a requirement for an actual popup warning message of some sort to prompt the user to make sure the date field is not blank.
How would I add this functionality?
In order to deliver the functionality you are looking for you have to use a "Custom Object". It is an object you put on the layout of the application in Archer that contains JavaScript code. This code will be executed as soon as the form of the application is loaded. There is a special type of the field "Custom Object" available in the Layout editor for each application in the Application Builder in Archer.
Note - I don't recommend to use custom objects in general and neither RSA Support. Every time you modify the layout in the given application, you have retest and sometimes correct IDs for your custom object. You can write an ID independent custom object and use field names, but in this case custom object will have more code. I prefer to make custom objects as short as possible.
Your custom object should do the following:
Override the behavior of the "Save" and "Apply" button in the top tool bar available for every application form in Archer.
Once "Save" and "Apply" buttons are "overwritten", every time they are clicked on your function will be called. So you need to create a click handler function.
Your click handler function will check values user is required to populate and will either return warning, or will call the original handler for "Save/Apply" buttons.
This is a code template you can start with:
<script type="text/javascript">
// ids are used to locate buttons
var buttons_ids = [
"master_btnSave", // "Save" button ID
"master_btnApply" // "Apply" button ID
];
// parameters are used in the "onclick" default handlers to call original handlers
var buttons_parameters = [
"master$btnSave", // "Save" parameter
"master$btnApply" // "Apply" parameter
];
document.getElementById(buttons_ids[0]).onclick = function(){ Validator_of_required_fields(buttons_parameters[0])};
document.getElementById(buttons_ids[1]).onclick = function(){ Validator_of_required_fields(buttons_parameters[1])};
// end of the script body
//==== Validator function attached to Save and Apply buttons
function Validator_of_required_fields(parameter){
// ids of the input fields to validate
var inputs_to_validate_ip_address = [ "master_DefaultContent_rts_XXX_YYY_t" ];
// jQuery selector is used here. Archer v5.x has jQuery library loaded by default
// you will need to modify this selector
var field_value = $('#'+inputs_to_validate_ip_address[0]+':first').val();
if(field_value.length = 0) {
// Here you are calling Archer Warning function
var msg = "[Text to display to user]";
var title = 'Required Field';
WarningAlert(msg,title);
return false;
};
// default onclick processor
ShowAnimationAndPostback(parameter);
return false;
};
Some comments on this code:
You will need to modify the validation function to work with values stored in the fields you need.
I used a rather 'unusual' way to override the behavior of the "Save" and "Apply" buttons using the following code:
document.getElementById(buttons_ids[0]).onclick = function(){ bla, bla, bla }There are simpler way to do the same, but this way custom object works fine in IE8-11, FF, Chrome and Opera. Let me know if you find a simpler way to override buttons that is browser agnostic.
Function WarningAlert(msg,title); is a build-in Archer warning message function. It worked fine in Archer v5.4. You might need to use simple JavaScript Alert function if WarningAlert doesn't work in your version of Archer.
Note that behavior of the "Save" and "Apply" buttons might be overwritten back to default in case if user opens up any pop-up dialog windows to populate a value list or cross-reference field. If that is the case, you will have to wrap the code provided into another function and attach it to the OnLoadWindow event (or similar).
I try to avoid using any JavaScript libraries in my custom objects. This way it is simpler to support them and you have less dependencies. I used jQuery in the provided example only because Archer already uses this library once the page is loaded.
Flak, make sure to test your custom object very well and good luck!
attempting to call $(this).fineUploader("getButton", id); in the submit event handler and getting undefined as a result.
I assume the buttons are being tracked since access to the button is available within the validate and upload events. However, I really would like to know which button was clicked during the submit event so I can set parameters for the specific file upload. The validate event has no file id present to associate specific parameters
In Response to Comments, additional information:
Fineuploader Version 4.1.1
I have tried the scenario in many configurations and getButton method call never works in the submit handler
myfineuploader.on('submit', function(event, id, name) {
var button = $(this).fineUploader('getButton', id);
console.log(button); // Button always shows undefined here
}
The buttons are defined as spans outside of the template, setup like this in the config:
button: $("#button1"),
extraButtons: [
{
element: $("#button2")
}
]
The button is not associated with the file until after the submit event callback has completed. This was done to ensure that mappings were created only for files that passed all possible validation steps, since it is possible to reject a file in your "submit" handler as well. After some thought, it may be best to create this button to file mapping as soon as we have created an ID for this file internally. I've created an item in our issue tracker to deal with this.
If you move your logic into a "submitted" event handler instead, you should be good to go.
This question already has an answer here:
How to monitor asynchronous/background thread status and get notifications in a JSF component
(1 answer)
Closed 6 years ago.
I want a inputTextarea to display lines appended to some text file. I imagine it like this: The user clicks a commandButton that does a AJAX call.
My problem is: The text will only be rendered when the action returns. However, my action should look like this:
while(true) {
String newData = getSomeMoreDataFromServer();
// append the new data to a textarea and the user should see it immediately
if(blabla) { break; }
}
Is this even possible? The part that's commented out is the part that bothers me.
Can the user even set the break condition in the form somehow?
I'm using JSF 2 (MyFaces) + Tomahawk.
That's not possible from inside the backing bean action method. Also having a while(true) is very CPU-inefficient, you'd rather like to avoid that in a multi-user environment. What you're looking for is ajax poll/push. This is not provided in the standard JSF implementation and also not in Tomahawk. PrimeFaces for example, supports ajax poll/push components <p:poll> and <p:push>.
I have a dialog in vb6 which changes the values being displayed in its parent dialog.
The x1 is displayed in txt_c1 text in parent dialog and it has a txt_1validate function too for the text box. Now i want to change the value of txt_c1 txtbox from child dialog and then call its validate function. But the problem is that txt_c1 is not available in child dialog.
Please note that i am working in vb6 in the MS VB 6.0 IDE
Forms are just classes and can therefore be instantiated explictly (and you will probably find your life easier if you do rather than using the automatic instantiation in VB6) and references to forms can be assigned.
You can solve your problem by creating a public property on your child dialog (Form1.frm) of type Form that you set to the instance of the parent dialog thus giving you access to the controls andd methods on the parent from the child.
My VB6 is somewhat rusty (and I don't have an installed instance available) so this isn't going to be actual, correct code - but something along the lines of the following should work
In the code that calls the child:
Form childDialog = new Form1
childDialog.Parent = this
childDialog.ShowModal
Then in the child dialog:
Parent.txt_c1 = newValue
if not Parent.Validate then
...
end if