Call javascript function on AutoHotKet - autohotkey

I have requirement to send information to third party tool and fetch some information from this tool using autohotkey.
but i am facing informaiton into textbox and try to fire button click event .
I have used this code to fill the textbox and fire button click event but not able for fire this because textbox event not fired as mention in below code..
pwb.document.getElementsByTagName("input")["rio-search"].focus()
pwb.document.getElementsByTagName("input")["rio-search"].value := startelemnet
fullvalue :=pwb.document.getElementsByTagName("input")["rio-search"].value
Sleep, 500
pwb.document.getElementsByTagName("input")["rio-search"].value := fullvalue
pwb.document.getElementsByTagName("input")["rio-search"].focus()
wbs.document.parentWindow.showOptions()
wbs.document.parentWindow.execScript("showOptions()")
pwb.document.querySelector("button[type=submit]").Click()
but i am try to call the javascript mehtod on textbox focus in autohotkey but not able to call :
<input type="text" id="rio-search" ng-model="$root.keywords" ng-focus="showOptions()" ng-blur="hideOptions()" class="form-control ng-valid ng-touched ng-dirty ng-valid-parse" placeholder="Search">
Please provide me the solution for this.

Have you even defined pwb and wbs?
Since your website seems to use angularJS, make sure you wait until the site is actually completely generated.
Also, it is likely not a function, but a method of the angular $scope.
So your js code might have to look somewhat like this:
var scope = angular.element($("#outer")).scope();
scope.showOptions()
But the method might expect some kind of "this" or similar of the input element. So I have no idea if this would work.
You might also wanna check:
xx.document.InvokeScript("functionName");

Related

Dynamically loading content through Groovy server page upon form submit

I have a Groovy project (vanilla; no Grails) with an index.gsp that takes form input from the user and sends it in a POST request to a Groovy script. The form is set up like this:
<form action="somewhere" method="POST" enctype="multipart/form-data">
// some other inputs
<input type="submit"/>
</form>
Is there any way (ideally not using Javascript) to dynamically load content on the same page after the user submits? Redirecting to another GSP might also work. Just something simple, like a string containing whatever the user typed. It seems like Grails has plenty of options, but unfortunately I can't use it.
As you mentioned, Grails is capable of doing what you need without any complex code. Since you can't use it, you will have to use JQuery(Javascript) to make an AJAX call. AJAX is the he only way that I know to achive that.
Just make an AJAX call to your groovy script. JQuery.ajax has a success function to be called if the request succeeds. You can use it to update a hidden dive after the form. This success function has the data returned from the server as an argument, that data could be the string containing whatever the user typed. In that case just add the data to the hidden div and then make that div visible.
function onSucceed(data) {
$('#hiddenDivToUpdate').text(data);
$('#hiddenDivToUpdate').show();
}
You can learn about JQuery.ajax() in this link AJAX

Does Alfresco Share provide any mecanism for Inter Dashlet Communication?

I am trying to figure out how to perform some inter dashlet communication with Alfresco Share.
Here a simple use case:
We do have 2 dashlets, let's call them A and B. I want to be able to fill in a field "name" (let's say with value "Toto") in A and click on submit button. After clicking on submit button in A. B should be updated with greeting like " Good Morning Toto".
Thank you for you answers.
Thanks for your answer. Can you elaborate a bit regarding "let dashlet_b.get.html.ftl post something to dashlet_a.post.html.ftl" ?
In dashlet_b.get.html.ftl you have something like that I guess :
<form id="..." action="" method="POST">
<input id="name" type="text" name="name" value=""/>
<input type="submit" id="send" value="Send" /></form>
When you submit the form it's gonna look for dashlet_b.post.js right ? How do you actually tell to send the form to dashlet_a.post.js ?
To create these dynamic dashlets it is not enough to use the server side dashlet webscript. You need javascript logic in the browser to notify the other dashlet of changes. This is how Alfresco usually does that:
Browser Javascript Dashlet A:
YAHOO.Bubbling.fire("interDashletMessage",
{
message: "Hello World."
});
Browser Javascript Dashlet B:
YAHOO.Bubbling.on("interDashletMessage", function(layer, args) {
var message = args[1].message;
alert(message); // or write it to the dashlets HTML content
});
This will send the message from dashlet A to dashlet B using a custom event called "interDashletMessage".
If your dashlet B only displays a few messages it could be enough to send the data over using the events. If it is more complex your dashlet A needs to post it's data to the repository first, then trigger the "refresh" event and have dashlet B refresh it's content from the repository. This will involve multiple webscripts you may need to write.
That's quite simple I guess.
Each Dashlet is in fact a webscript. So you can have multiple webscript for different usage. Like I've got dashlet_a.get.html.ftl and dashlet_a.post.html.ftl.
In fact these two are the same webscript, one just acts on a post and the other on get.
So what you could do, is let dashlet_b.get.html.ftl post something to dashlet_a.post.html.ftl. Hence you are submitting value(s) from b to a.
The next step is to refresh dashlet_a, one way is to do a full page refresh, but that's not nice.
Whats better is the following:
In dashlet_a.post.html.ftl you just set through YUI/JQuery the value of the field which is defined in dashlet_a.get.html.ftl.
Take a look how the default configurable dashlet do it, like the webview. If you put something in the config, the value directly is shown.

Yii - How to call external javascript on every CActiveForm validation?

I would like to make a "preview container" for form values in Yii. (so every time the user finishes entering data, the "preview container" below the form will display them, to let the user knows how the item actually looks like).
To achieve this, the only way is to call a Javascript function to update the "preview container" (using jQuery). The CActiveForm is:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id'=>'item-form',
'enableAjaxValidation'=>true,
));
?>
How do we modify it to call a javascript function each time the fields are validated?
(Note: whenever we switch between the input fields, the fields are validated dues to enableAjaxValidation=>true)
Thanks in advanced.
With jQuery you can define your own listener functions for the fields you want to update, which is probably going to be cleaner than trying to hook into the validation functions.You could monitor onchange or blur or whatever is most appropriate to your data.
The js can be loaded via Yii's registerScript function or, again, whatever is most appropriate for your app. A listener function would normally be loaded on DOM ready, i.e., with the POS_READY attribute for registerScript.
You can search the tutorials as well as this basic tutorial for more info.

Prevent double-clicking on Button

I keep having an issue with users double-clicking on action buttons on my web application, which is meaning duplicate records are being added into my database, and sometimes the user is being charged twice (as the action is being ran twice).
What is the best way of preventing double clicking in ASP.NET?
I see you're concerned about this in the face of users without javascript enabled. If that's the case, you need to deal with it on the server side. One idea to deal with this would be to implement CSRF tokens throughout your app.
This basically keeps a token in the server side session, and also requires the token to be submitted in the request. Provided youreset this token in the session in a timely manner (and assuming that you're using usual ASP.Net mechanisms to serialize access to the session), the second request will be using an out of date token, and can be ignored.
I think the best solution would be to disable button after clicking using Javascript. Try adding onclick function to it:
<input type="submit" onclick="disable_button(this);" />
<script type="text/javascript>
function disable_button(sender){
sender.disabled = true;
}
</script>
It can also be done using server-side code using server controls. Paste this into your pre-render or page_load event:
yourButton.Attributes.Add("onclick", " this.disabled = true; "+ ClientScript.GetPostBackEventReference(Button1,null)+";");
This will basically disable the Button when ever u click it and then calls the server side code as if the button has been clicked.
Have you tried adding a little JavaScript to the submit button?
e.g.
<input type="button" onClick="formSubmit.disabled=true;">
This way the button is disabled right after the first click and won't take the second click ...
I solved this problem by using a session variable without enabling or disabling the button.
In the Page_Load add :
Session["clicked01"] = "0";
in the btnSave_Click :
if (Session["clicked01"] == "1")
{
return;
}
/// save the record
Session["clicked01"] == "1"

How to clear the form when the user doesn't provide valid username/password

I designed a form as follows:
User Name: _______________
Password: _______________
Login
I also use jQuery Form Plugin to submit the form to the server side.
It will return if the server script finds some errors. The data returned by server is in JSON format. I would like to know how I can reset the user name + password when I know the username/password is invalid in a decent way.
In other words, I can manually use jQuery to empty the username/password field if the returned result indicates a failure. In fact, I am looking for a decent way built in Form Plugin or sth else that can do this part me for automatically. The only thing I have to do is to set a flag so that if the submission is failed, then the form will be resetted.
Thank you
You cam simply do:
$('#form_id').reset();
I don't think you need a plugin for such simple task. You simply call above code based on the response.
Run this.form.reset() when a form button (e.g. Reset) is being pressed.
e.g.
<form>
...
<input type="button" value="Reset!" onclick="this.form.reset();">
</form>