I have an input text box, a button and a kendo grid. The datasource for the kendo grid is Rest webservice url. My Rest web service needs an input parameter on the basis of which it sends the appropriate json data. My requirement is whenever I click on the button it takes the data from the input box, appends it to the Rest url as its input param, fetches and display the corresponding data from web service. If I change the value in input text box and click on button again then the kendo grid should be refreshed with new set of data returned from web service. Below is my code.
HTML:
<div ng-app="myApp">
<div ng-controller="myCtrl">
<div>
<form>
Enter Param
<div>
<input type="text" ng-model="param">
</div>
<button type="submit" ng-click="submitParam()">Submit</button>
</form>
</div>
<div id="grid" kendo-grid k-options="kendoGrid"></div>
</div>
</div>
Controller:
var myApp = angular.module('myApp',[]);
myApp.controller('myCtrl', function ($scope, myService) {
$scope.param = "";
$scope.kendoGrid = myService.getKGrid();
$scope.submitParam = function(){
**//here param should be appended in the Rest URL and kendo grid data should change as per the** new URL.
}
});
Service:
myApp.service('myService', function () {
this.getKGrid = function () {
var kGrid = {
dataSource: {
transport: {
read: {
url: MyRestURL/param,**//Here the param will be appended**
dataType: "json"
}
},
},
columns: [{
field: "Col1",
title: "Col1"
},
{
field: "Col2",
title: "Col2"
}
]
};
return kGrid;
};
});
I am able to resolve the problem by changing the Datasource URL dynamically by using grid.dataSource.transport.options.read.url property of Grid datasource.
Reference link: Kendo UI Dynamically Change Datasource String (XML)
Related
So, I have a form that contains a textarea field and a submit button:
<form class="popupForPosting">
<textarea id="postContent" name="postContent" rows="8" cols="80" class="postContent" placeholder="What's going on, <?php echo $firstname ?>?"></textarea>
<button id="pos" class="pos" onclick="makePost()">Post</button>
</form>
When I click my submit button, the call gets sent to my AJAX as a request and my postContent (whatever is entered in the textarea field) gets shown in the URL. I don't want this to happen.
Now, I don't want to use the POST method for this form. I want to use the GET method, but still hide the parameters displayed in the URL. According to the information and details given, how can I accomplish this?
EDIT:
<script>
const makePost(form) {
const text = form.postContent.value;
function makePost() {
var postContent = $("#postContent").val();
if (postContent.length > 0) {
jQuery.ajax({
url:"yourposts.php",
data:{
postContent: postContent
},
type:"POST",
success:function(data){
if (data == "success") {
$(".textpostFormat").html(postContent);
}
}
});
}
}
};
document.querySelector(".popupForPosting").addEventListener("submit",function(e) {
e.preventDefault();
makePost(this); // passing the form
});
</script>
Simplest answer for you
Change the form tag: action="yourposts.php" method="post"
Give the submit button an name and a value and remove the click handler
move your post.php to the top of the page
add a test isset($_POST["submitButtonName"])
empty the form field before returning the page
remove all ajax related script
Now the page will save the data if the button is clicked and not if the page is just loaded. The test for content will handler the reload
Ajax answer
Using AJAX does not show the data in the URL - just
remove onclick="makePost()"
use the submit event of the form instead of the click event of a submit button and use event.preventDefault():
NOTE I have wrapped in a load event handler
$(function() { // when form is available
$(".popupForPosting").on("submit", function(e) {
e.preventDefault(); // always prevent submit
const postContent = $("#postContent").val().trim();
$('#noText').css({visibility: postContent === "" ? "visible" : "hidden" })
$("#popUp").toggle(postContent==="")
if (postContent) {
$.ajax({
url: "yourposts.php",
data: {
postContent: postContent
},
type: "POST",
success: function(data) {
console.log(data)
if (data == "success") {
$(".textpostFormat").html(postContent);
}
}
});
}
});
});
I've spent all day searching high and low for an answer to my problem and just can't find one.
Can someone please suggest a simple way I can get the value of the input field as a parameter in my Ajax call?
I would rather it stayed as an #Ajax.ActionLink call if possible.
Thanks.
<div class="form-group ui-widget">
<input class="form-control" id = "Reference" type = "text" />
</div>
<div>
#Ajax.ActionLink("Select","SelectedReference","Home",
new { reference = ?????????? },
new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "Results",
InsertionMode = InsertionMode.Replace,
OnBegin = "OnBeforeReference",
OnFailure = "OnAjaxError",
OnSuccess = "hideReference"
},
new
{
id = "referenceSelectButton",
#class = "btn btn-success"
})
</div>
Can I get the value of the input field as a parameter in my Ajax call?
No, It's not possible to use #Ajax.ActionLink to fulfil your requirements.
Alternatively, You can use jQuery ajax to do this.
Just use a simple button:
<button class="btn btn-success" id="referenceSelectButton">Select</button>
And on button click use jQuery ajax request to do all your work done.
#section Scripts{
<script type="text/javascript">
$('#referenceSelectButton').click(function () {
var referenceVal = $('#Reference').val();
$.ajax('#Url.Action("SelectedReference","Home",new { reference="-1"})'.replace('-1', referenceVal), {
method: 'post',
beforeSend:OnBeforeReference,
success: function (response) {
$('#Results').html(response);
hideReference();
},
error: OnAjaxError,
});
});
</script>
}
I have placed the jquery script code inside #section so that It's placed after jQuery scripts. Hopefully, this will resolve your problem.
I have a component which iterates through an array of areas which all have unique id's. When you click the button it opens a dialog which contains a iframe which listens to an eventlistener and retrieves data as JSON and sends it via post to a INSERT method in my ASP.NET CORE API.
I'm now also trying to send the id of the area and right now I only pass it as a paramter on the openDialog function.
planner.component.html
<div *ngFor="let area of areas">
<div class="area-container">
{{area.areaId}}
<button (click)="openDialog(area.areaId)" type="button" class="btn btn-primary btn-rounded">+</button>
</div>
</div>
planner.component.ts
The dialog opens with the iframe and right now only logs the id of the area.
openDialog(id: number) {
let dialogref = this.dialog.open(IframeComponent, {
width: '120vh'
});
console.log({areaId:id}) // like this {areaId: 20}
this.plannerService.getData(this.id);
dialogref.afterClosed().subscribe(result => {
console.log(`Dialog closed: ${result}`);
this.dialogresult = result;
})
}
in the service i have a eventListener which stores data from the iframe and sends it to my ASP.NET Core API as JSON
You can see here that I'm trying to send in an id but i don't know how to get the value from the planner.component which makes it undefined.
.planner.service.ts
getData(id: number) {
window.addEventListener("message", (e) => {
let data = JSON.parse(e.data)
console.log(data);
console.log({areaId: id})
this.createResource(data, id).subscribe(data => this.resources.push(data));
}, false);
}
data from iframe as JSON
{id: 282970, title: "page 1", description: "", thumbnail: "https://site/image/resourc…umbnail?guid=a0b67c13-ead4-49e0-a576-b4c8be1491b2", url: "https://site/l/show.html#PZWQz", …}
description: ""
guid: "a0b67c13-ead4-49e0-a576-b4c8be1491b2"
id: 282970
thumbnail: "https://site/image/resourcethumbnail?guid=a0b67c13-ead4-49e0-a576-b4c8be1491b2"
title: "page 1"
url: "https://site/l/show.html#PZWQz"
{areaId: undefined}
the question is how can a pass the value of the areaId inside the planner.component (which now only gets logged) to my service method so that i can pass it to my API?
In your component, you can inject your planner service and call its method
Assuming your service name is PlannerService
You component contructor would be like this:
constructor(private plannerService: PlannerService) {
}
And then in your method you can do this:
openDialog(id: number) {
let dialogref = this.dialog.open(IframeComponent, {
width: '120vh'
});
console.log({areaId:id}) // like this {areaId: 20}
this.plannerService.getData(id) <-- here id is the parameter you want to send
dialogref.afterClosed().subscribe(result => {
console.log(`Dialog closed: ${result}`);
this.dialogresult = result;
})
}
So I'm trying to develop a so called "Web Content Widget" to use in the SAP Cloud Portal, as described here: https://help.sap.com/viewer/3ca6847da92847d79b27753d690ac5d5/Cloud/en-US/b3b13c6b75244a18887180353ce49599.html
What I'm trying to create is a title with an icon next to it. Clicking the icon should open a popover with some text.
The title and the popover text should be configurable from the Cloud Portal.
Right now I have a configurable title and configurable text, but how do I implement a mechanism to open and close the popover in that framework?
Is there a way to use event handlers in a "Web Content Widget"?
Or perhaps: Is there a way to use sap.m.popover?
(i.e. Transforming a SAPUI5 app in a portal widget and adding options? But how?)
Edit:
Folder structure looks like this:
CustomContentWidget
ContentUnits
popover.json (contains the "settings/configuration" that can be edited in the Portal)
renderers
popoverRenderer.js
snippets
popover.html
Component.js
manifest.json
cp.app.descriptor.json
The "popoverRenderer.js and "popover.html" snippet:
sap.ui.define([
"sap/ushell/cpv2/services/control/contentUnit/WebContentRenderer"
], function(WebContentRenderer) {
"use strict";
return WebContentRenderer.extend("infoblockpopover.renderers.popoverRenderer", {
getDefaultSettings: function() {
var defaultSettings = {
height: "10rem"
};
return defaultSettings;
},
onInit: function() {
},
onThemeChanged: function() {
},
createSettingsEditor: function(propertyEditorManager) {
var propertyEditor = propertyEditorManager.editor;
this.addPropertyEditor({
key: "height",
category: propertyEditorManager.bundle.getText("WIDGET_CATEGORY_DIMENSIONS"),
title: propertyEditorManager.bundle.getText("WIDGET_SETTINGS_LABEL_HEIGHT"),
editor: propertyEditor.Size,
flags: propertyEditor.Size.AUTO | propertyEditor.Size.UNIT_PX | propertyEditor.Size.UNIT_PT | propertyEditor.Size.UNIT_REM
});
},
renderer: {
render: function(oRm, oControl) {
var settings = oControl.getSettings();
oRm.write("<div");
oRm.writeClasses();
oRm.writeControlData(oControl);
oRm.write(">");
oRm.write("<div>");
var uiComps = oControl.getItems();
jQuery.each(uiComps, function() {
oRm.write("<div style='position: relative;height:" + settings.height + "'>");
oRm.renderControl(this);
oRm.write("<div style='clear: both'></div>");
oRm.write("</div>");
});
oRm.write("</div>");
oRm.write("</div>");
}
}
});
}, true);
<component>
<style>
/* Some style here */
</style>
<div class="{$dir} {$device}">
<div class="zBILink ['{popoverText}'?'':'zBILinkHide']" >
<span class="icon-wl-icon-question onclick-menu" tabindex="0">
<div class="onclick-menu-content">{popoverText}</div>
</span>
</div>
</div>
</component>
I'm using a kendo ui grid, and I want to bind the columns headers to a json file, instead of specifying it directly in the controller.
I created a function that successfully retrieves the array from the json file, and populate the scope:
function returnColumns(){
$http.get('app/data/headers.json')
.then(function(res){
$scope.myHeaders = res.data;
});
}
returnColumns();
And in the grid's options I'm referring the columns to that variable in the scope:
$scope.options = {
dataSource: {
type: "json",
transport: {
read: "app/data/myData.json"
},
pageSize: 10,
schema : {
data: "mySchema"
}
},
sortable: true,
pageable: true,
resizable: true,
columns:$scope.myHeaders
....
....
But the binding doesn't kick in, the headers are not updated.
Thanks!
Assuming you're only loading the headers once and it's okay to hide the table until the headers load, throw an ng-if="myHeaders" onto the kendo-ui grid element, remove columns from $scope.options and use k-columns on the element instead.
So:
<div kendo-grid k-options="options"></div>
becomes:
<div kendo-grid k-options="options" k-columns="myHeaders" ng-if="myHeaders"></div>