- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2019 11:53 PM
Hi All,
How to call onClick() function in Widgets?
Below is my html code in widget:
< input type="file" id="uploadFile">
<button type="button" ng-click=foo()> Upload </button>
Below is my client script code in the widget:
function foo()
{
var f=document.getElementById("uploadFile");
if(f.value!=''
{
alert("File is selected");
}
else{
alert("Nothing is selected");
}
This is not working. Instead it is firing onload. How to achieve it when the "Upload" button is clicked?
Thoughts!
Best Regards,
Ram
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2019 01:17 AM
Hi ram,
You need to call the function in your client side of the widget as below.
$scope.foo= function() {
//Put your code over here
};
Also, make sure that the $scope is also defined at the beginning of your client side.
//Refer the below line where the $scope is defined
function($scope,spUtil,$http,$timeout,$rootScope){
}
Hope this helps. Please mark the answer Correct/Helpful based on the impact.
Regards,
Amlan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2019 12:14 AM
Hi,
In the client script of the widget you should put in the function like this:
$scope.foo = function(){
//... your code...
}
ps. in the code you are showing you were missing an end brace "}" as well... but do it as above, that is how it should be.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2019 12:20 AM
Hi,
I tried the above mentioned step, but no luck. It is not working.
Regards,
Ram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2019 01:17 AM
Hi ram,
You need to call the function in your client side of the widget as below.
$scope.foo= function() {
//Put your code over here
};
Also, make sure that the $scope is also defined at the beginning of your client side.
//Refer the below line where the $scope is defined
function($scope,spUtil,$http,$timeout,$rootScope){
}
Hope this helps. Please mark the answer Correct/Helpful based on the impact.
Regards,
Amlan