I have a jquery save function like this -
$(".SaveBtn").click(function () {
if ($("#Form1").valid()) {
var rowData = $("#TestTable").getRowData($(this).data("rowid"));
var currentRow = $(this).closest("tr");
var postData = {
testID: rowData.testID,
testNotes: currentRow.next().find(".NotesEntry").val(),
isActive: currentRow.next().next().find(".CheckEntry") == null ? "false" : currentRow.next().next().find(".CheckEntry").prop("checked"),
};
$.ajax({
type: "POST",
url: "../Services/test.asmx/UpdateTestRowData",
data: JSON.stringify(postData),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data.d != null) {
$("#TestTable").setGridParam({ postData: { myID: $('#hfmyID').val() }, datatype: 'json' }).trigger("reloadGrid");
}
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
});
The problem is with this line -
isActive: currentRow.next().next() == null ? "false" : currentRow.next().next().find(".CheckEntry").prop("checked"),
};
When currentRow.next().next() is not available, the isActive is not set as "false" and is even not in the request body to web service.
Currently the request body is {"testID":"e9c966ace446-4f73-9ba0-26e686b2a308","testNotes":"TEST"}
I expect it to be -
{"testID":"e9c966ace446-4f73-9ba0-26e686b2a308","testNotes":"TEST", "isActive":"false"}
Why the "isActive" parameter is missed and how to make it available when currentRow.next().next() is not available?
Thanks
I fixed the problem by adding the else part in the following statement -
if (data.d.IsActived) {
output += "<td colspan='6' align=\"left\"><input type='checkbox' id='cbActive" + rowId + " checked" + " name='cbManualDeactive" + rowId + "' class='CheckEntry CheckEntry' data-registrationid='" + data.d.ID + "' data-rowid='" + rowId + "'/></td>";
}
else {
output += "<td style=\"display:none;\"><input type='checkbox' id='cbActive" + rowId + " name='cbActive" + rowId + "' class='CheckEntry CheckEntry' data-registrationid='" + data.d.ID + "' data-rowid='" + rowId + "'/></td>";
}
Thanks
Related
how can I do for this function below to generate an incremental index in the table? Names are being generated right.
I thought of an incremental variable (a), something like that.
function sortear()
{
var a = 1;
$.ajax({
url: 'prize',
type: 'POST',
dataType: 'json',
data: 'employees=' + $('#employees').val() + "&sorted=" + sorteados,
beforeSend: function() {
$('#loading').modal();
},
success: function(data) {
$('#loading').modal('hide');
if (data == null) {
window.alert('Todos os nomes foram sorteados');
$('#button').attr('disabled', 'disabled');
return;
}
$('#employee').html(data.name);
$('#myModal').modal();
$('#sorted tbody').append('<tr><td>' + a + '</td><td>' + data.name + '</td></tr>');
sorteados.push(data.name);
a++;
},
error: function() {
}
});
}
You can get the length of <tr> and sum 1:
/*...*/
// store the element in a variable to reuse it
const $sortedTbody = $('#sorted tbody');
// in the first iteration lenght will be 0, so it will print 1, then 2, etc
$sortedTbody.append('<tr><td>' + ($sortedTbody.children().length + 1) + '</td><td>' + data.name + '</td></tr>');
/*...*/
function sendEmailToUser(){
var msgTo = "cigma#gmail.com";
var msgFrom = "drrama#gmail.com";
var messageBody = " Your code is 1234567";
var msgSubject = "CODE";
$.ajax({
type: "POST",
url: "/services/Mail.asmx/SendMail",
cache: false,
contentType: "application/json; charset=utf-8",
data: "{ 'body':'" + messageBody + "'," +
"'to': '" + msgTo + "'," +
"'from': '" + msgFrom + "'," +
"'subject': " + msgSubject + "'" +
"}",
dataType: "json",
complete: function (transport) { if (transport.status == 200) $("#formcontainer").html("Success"); else alert("Please try again later"); }
});
}
This is my function in javascript code that is called when ever a button is clicked, so as to sent text to the specified email address as shown in the code, but the function always returns "Please try again later" as a error message. It does not sent a text to cigma#gmail.com
This is my first question on Stack Overflow.
I am developing a solution in SharePoint online and I have a list that has several items, I need to get the titles of those items and insert them in a RadioButtonList, so that, when a new item is added, the radio button can take the new item. Thanks!
Try to do it the way DropDownList, but it does not work...
function loadDdl(ddlId, list) {
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
$.ajax({
url: siteUrl + "/_api/web/lists/GetByTitle('" + list + "')/items",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
$.each(data.d.results, function (key, value) {
$("#" + ddlId).append($("<option></option>")
.val(value.Title)
.html(value.Title));
});
sortDropDownListByText();
},
error: function (error) {
alert(JSON.stringify(error));
loadingOff();
}
});
}
Inserting items into the DDL:
$(document).ready(function () {
// SP.SOD.executeFunc('sp.js', 'SP.ClientContext', initializePage());
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', revisarPermisos);
var emitidoPor = _spPageContextInfo.userDisplayName;
$("#lblEmitidoPor").append(emitidoPor);
loadDdl("ctl00_PlaceHolderMain_ddlEmisor", "Departamentos");
loadDdl("ctl00_PlaceHolderMain_ddlDepartamentoDeHallazgo", "Departamentos");
loadDdl("ctl00_PlaceHolderMain_accionesRdl", "Departamentos");
$("#hlNuevaSolicitud").addClass("active");
loadingOff();
});
This is the solution, and how to insert list item in a RadioButtonList
function loadRbl(RblId, lista) {
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
$.ajax({
url: siteUrl + "/_api/web/lists/GetByTitle('" + lista + "')/items",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
var i = 1;
$.each(data.d.results, function (key, value) {
$("#" + RblId).append($("<tr><td>"
+ "<input type='radio' id='" + RblId + i+ "'
name='ctl00$PlaceHolderMain$rdlAccion' value='" + value.Title
+ "'>"
+ "<label for='" + RblId + i+"'>" + value.Title + "</label>"
+ "</td></tr>"));
i++;
});
},
error: function (error) {
alert(JSON.stringify(error));
loadingOff();
}
});
}
When i click the Select working days / hours Checkbox the list of days will be displayed. for example if i click the sunday checkbox check box the value entered in the checkbox should be call to javascript function. in case am not click the checkbox the value display should be Null.
DEMO LINK HTML
$(document).ready(function () {
$("input#btnDocBusinesshours").click(function () { SaveDocBusinesshours(null) });
});
Call Ajax Function
function callAjax(jparms) {
$.ajax({
type: "POST",
url: jparms.url,
data: jparms.data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (jparms.action == "SaveDocBusinesshours")
SaveDocBusinesshours(response.d)
},
failure: function (response) { response.d; }
});
}
Save Ajax Function
function SaveDocBusinesshours(response) {
var values = $('input[type="checkbox"].single:checked').map(function () {
return $(this).val();
}).toArray();
if (response == null) {
callAjax({
url: pageUrl + '/SaveDocBusinesshours',
data: '{"Doctorid": "' + $("#<%=hdnDoctorId.ClientID %>").val() + '","WorkingDaysID" : "' + $("#<%=hdnBusiness.ClientID %>").val() + '","Sunday" : "' + $("#<%=ChkSUN.ClientID %>").val() + '","Monday" : "' + $("#<%=ChkMON.ClientID %>").val() + '","Thuesday" : "' + $("#<%=ChkTUE.ClientID %>").val() + '"}',
action: "SaveDocBusinesshours"
});
window.location.reload();
}
else {
loading(false);
if (response.AjxContactId != null) {
$('#<%=hdnBusiness.ClientID%>').val(response.AjxContactId);
}
msg(true, response.Message);
}
}
Webmethod:
[WebMethod]
public static UserAjax SaveDocBusinesshours(string Doctorid, string WorkingDaysID, string Sunday, string Monday, string Thuesday)
{
UserAjax oUserAjax = new UserAjax();
return oUserAjax;
}
I have a problem with saving new records in kendo grid. When I update the grid it works normally, when I try to add new records, it doesn't. When I try to investigate the problem in debugger, network, I got this during POST process (last qutation mark is missing):
{ "Comment": "","OrderType": "43434343","Amount": "0","Status": "0","_MaterialKey": "83000000000","StartTime": "Tue Jun 02 2015 10:43:17 GMT+0200 }
here is the part of my parameter map:
transport: {
read: {
url: $("#gatewayPath").data("value") + "odata/ods/Plannings?$expand=Material($select=_Key,MaterialLocalName,MaterialGlobalName)&$select=_Key,OrderType,Amount,StartTime,Comment,Status",
datatype: 'json',
beforeSend: function (x) {
var auth = $("#authenticationType").data("value") + " " + $("#authenticationToken").data("value");
x.setRequestHeader("Authorization", auth);
}
},
if (operation === "create") {
return '{ "Comment": "' + ((!data.Comment) ? "" : data.Comment) +
'","OrderType": "' + ((!data.OrderType) ? "" : data.OrderType) +
'","Amount": "' + ((!data.Amount) ? "0" : data.Amount) +
'","Status": "' + ((!data.Status) ? 0 : data.Status) +
'","_MaterialKey": "' + ((!data.Material) ? "83000000000" : data.Material._Key) +
'","StartTime": "' + ((!data.StartTime) ? 0 : data.StartTime) +
' }';
}
else if (operation === "update") {
if (data._Kendo_SaveIt == 1) {
data._Kendo_SaveIt = 0;
return '{ "_Key": "' + data._Key +
'","StartTime": "' + kendoHelper.getDate(data.StartTime) +
'","OrderType": "' + data.OrderType +
'","Amount": "' + data.Amount +
((data.Material) ? '","_MaterialKey": "' + data.Material._Key : "") +
'","Comment": "' + data.Comment +
'","Status": "' + data.Status +
'"}';
}
}
create: {
url: function (data) {
return $("#gatewayPath").data("value") + "odata/ods/Plannings?$expand=Material($select=_Key,MaterialLocalName,MaterialGlobalName)&$select=_Key,OrderType,Amount,StartTime,Comment,Status";
},
dataType: "json",
type: "POST",
beforeSend: function (x) {
var auth = $("#authenticationType").data("value") + " " + $("#authenticationToken").data("value");
x.setRequestHeader("Authorization", auth);
}
},
update: {
url: function (data) {
return $("#gatewayPath").data("value") + "odata/ods/Plannings(" + data._Key + ")?$expand=Material($select=_Key,MaterialLocalName,MaterialGlobalName)&$select=_Key,OrderType,Amount,StartTime,Comment,Status";
},
dataType: "json",
type: "PATCH",
beforeSend: function (x) {
var auth = $("#authenticationType").data("value") + " " + $("#authenticationToken").data("value");
x.setRequestHeader("Authorization", auth);
}
},