Lightbox Not Working with jQuery - ajax

I have a problem with lightbox after loading the following script in my page:
jQuery.validator.addMethod('answercheck', function (value, element) {
return this.optional(element) || /^\b5\b$/.test(value);
}, "please type the correct answer (this is anti-spam)");
// validate contact form
$(function() {
$('#contact').validate({
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
answer: {
required: true,
answercheck: true
}
},
messages: {
name: {
required: "please enter your name",
minlength: "your name must consist of at least 2 characters"
},
email: {
required: "please enter your email address"
},
answer: {
required: "sorry, wrong answer! (this is anti-spam)"
}
},
submitHandler: function(form) {
$(form).ajaxSubmit({
type:"POST",
data: $(form).serialize(),
url:"process.php",
success: function() {
$('#contact :input').attr('disabled', 'disabled');
$('#contact').fadeTo( "slow", 0.15, function() {
$(this).find(':input').attr('disabled', 'disabled');
$(this).find('label').css('cursor','default');
$('#success').fadeIn();
});
},
error: function() {
$('#contact').fadeTo( "slow", 0.15, function() {
$('#error').fadeIn();
});
}
});
}
});
});
I have read about .live() and read this page http://api.jquery.com/live/ but I am a newbie and have trouble implementing it in my script. Any help please?
thank you

Related

kendu ui grid after server update cells stay marked as "dirty"

i based this code on kendu grid ui code demo.
when ever i add a new record, it gets sent to the server side (c# handler)
and from there i convert json to object.. and so on.
the operation is successful and the request that kendu made is done with status code 200.
but for some reason the cells that were changed are still marked as "dirty" .
as a result of this any new row is sent with the first attempt since it thinks it needs to be sent again. here is my code:
jQuery("#getallDataBTN").click(
function () {
$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "/WallEHandler.ashx?command=getallPermissions",
dataType: "json"
},
create: {
url: "/WallEHandler.ashx?command=addPermission",
dataType: "json",
type:"post"
},
update: {
// url: "/WallEHandler.ashx?command=editPermission",
// dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id:"Method",
fields: {
Method: { type: "string" , validation: { required: true }},
ServiceType: { type: "string" ,validation: { required: true }},
Role: { type: "string" ,validation: { required: true }},
Permission: { type: "string" ,validation: { required: true }},
ExtendedData: { type: "string" }
}
}
},
pageSize: 100,
batch: true,
},
height:850,
scrollable: true,
sortable: true,
filterable: true,
pageable: {
input: true,
numeric: false
},
columns: [
"Method",
"ServiceType",
"Role",
{ field: "Permission", editor: categoryDropDownEditor },
"ExtendedData"
],
navigatable: true,
toolbar: ["create", "save", "cancel"],
editable: true
//selectable: "row",
//save: function(e)
// {
//alert("Save");
// }
});
}
);
is there maybe somthing i need to return from the server to tell the grid that it was successful?
thanks for any help
i figured it out, it seems that the response of a successful request must return the same object as sent. (must be some sort of inside validation by kendu).
c#:
Response.Write(context.Request.Form["models"]);

Kendo ui grid filed with editor, pop up won´t close

I have a field on my kendo ui grid which uses an editor:
columns:[{ field:"Nome", title: "Nome" },{ field: "idTipoQuarto", title:"Tipo de Quarto", editor: tipoQuartoEditor},
In my model i have:
schema:
{
data: "data",
total: function(response)
{
return $(response.data).length;
},
model:
{
id: "idQuarto",
fields:
{
idQuarto: { editable: false, nullable: true },
Nome: { validation: { required: true } },
idTipoQuarto: { validation: { required: true }}
}
}
}
And my editor function is:
function tipoQuartoEditor(container, options)
{
$('<input data-text-field="Nome" data-value-field="Nome" data-bind="value:' + options.field + '"/>').appendTo(container).kendoDropDownList({
autoBind: false,
dataSource: new kendo.data.DataSource({
transport:
{
read:
{
url: "data/quartos.php",
},
parameterMap: function(options, operation)
{
if (operation !== "read" && options.models)
{
return {models: kendo.stringify(options.models)};
}
}
},
schema:
{
data: "data",
model:
{
id: "idTipoQuarto",
value: "Nome"
}
}
})
});
}
I can see the values when my popup is opened in the drop-down list, and i can post the selections to my database when clicking on the update/insert button, but the popup won´t disappear. It shows me an error that i don´t understand:
Object {xhr: Object, status: "parsererror", errorThrown: SyntaxError: Unexpected token A, sender: ht.extend.init, _defaultPrevented: false…}
What am i missing here, i have seen another post but with no luck adapting to my problem.
Anyone?
Thanks for your time, regards

InCell Editing in Kendo UI and Web API

I am new to Web API and Kendo UI. My requirement is InCell Editing. I have implemented this with below reference links. But my problem is In controller action method i am getting count of employee as 0. I am not any other things means edited rows.
http://demos.telerik.com/kendo-ui/grid/editing
http://demos.telerik.com/aspnet-mvc/grid/editing
and another way I tried with below reference. But here also in JQuery I am getting what I updated rows. but when passing data to controller through AJAX call in controller I am getting count as 0. Please can you help this.
http://stackoverflow.com/questions/17033025/kendo-grid-batch-editing-making-a-single-call-to-save
Here is my code:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/api/Employee/GetEmployee",
dataType: "json"
},
create: {
url: "/api/Employee/CreateEmployee",
dataType: "json",
type: "POST",
complete: function (jqXhr, textStatus) {
// Do something
}
},
update: {
url: "/api/Employee/Update",
dataType: "json",
type: "POST",
complete: function (jqXhr, textStatus) {
// Do something
}
},
destroy: {
url: "/api/Employee/DeleteEmployee",
dataType: "json",
type: "DELETE",
complete: function (jqXhr, textStatus) {
// Do something
}
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 12,
schema: {
model: {
id: "Id",
fields: {
Id: { editable: false, type: "number" },
EmployeeId: {
editable: true, type: "text", validation: {required: true },
},
EmployeeName: { validation: { required: true } }
}
}
}
});
if (container.find('#gridEmployee').data().kendoGrid)
container.find('#gridEmployee').data().kendoGrid.destroy();
container.find("#gridEmployee").kendoGrid({
dataSource: dataSource,
pageable: true,
// toolbar: [{ text: "Add new Employee", className: "btn btn-primary grid-add-new-record" }, { text: "Save", className: "btnKendoUiSave" }],
toolbar: ["create", "save", "cancel"],
columns: [
{
command: [
//define the commands here
{ name: "edit", text: " " }, { name: "destroy", text: " " }, { name: "update", text: " ", click: showDetails }], width: "200px"
},
{ field: "EmployeeId", title: "Employee Id", format: "{0:0}", headerAttributes: { "data-localize": "FIELD_NUMBER" } },
{ field: "EmployeeName", title: "Employee Name", headerAttributes: { "data-localize": "FIELD_NAME" } },
],
editable: true,
});
Web API Controller:
[HttpPost]
public System.Web.Mvc.JsonResult Update([System.Web.Mvc.Bind(Prefix = "models")]List<PlantEmployeeModel> Employees)
{
//
}

When I add remote to Jquery Validate form submits when invalid

When I add remote to the jquery validate my form submits even if there are errors, when I remove remote it works properly and you can't submit the form and unless you have filled in all fields? Any ideas? code is below
<script>
$(document).ready(function () {
$("#SignUp").validate({
onsubmit: true,
onkeyup: function(element) { $(element).valid(); },
rules: {
email: {
required: true,
email: true
},
password: {
required: true,
password: true
},
confirm_password: {
equalTo: "#password",
required: true
},
company: {
nls:true,
required: true
},
telephone: {
required: true,
phoneUK: true
},
email2: {
email: true
},
website: {
url: true
},
address1: {
nls:true
},
address2: {
nls:true
},
town: {
nls:true
},
postcode: {
postcodeUK:true
},
country: {
selectcountry:true
},
terms:{
required:true
},
answer:{
remote: "Captcha/check-captcha.php",
type: "POST",
data: {
captcha: function() {
return $("#answer").val();
}
}
}
},
messages:{
email:
{
required: "Please Enter an Email Address"
},
password:
{
required: "Please Enter a Password"
},
confirm_password:
{
required: "Please Confirm Your Password"
},
company:
{
required: "Please Enter Your Company/Climbing Gym Name"
},
telephone:
{
required: "Please Enter a Telephone Number"
},
terms:
{
required: "Please Agree Our Terms and Conditions"
},
answer:{
remote: "You Have Entered The Captcha Correctly When This Message Disappears"
}
}
});
$.validator.addMethod("password", function (value, element) {
return this.optional(element) || /^[A-Za-z0-9!##$%^&*()_]{6,16}$/i.test(value);
}, "Passwords are 6-16 characters");
$.validator.addMethod("nls", function(value, element)
{
return this.optional(element) || /^[a-zA-Z0-9\s.\-_']+$/i.test(value);
}, "Please Only Enter Alpha Numeric Characters and Spaces");
jQuery.validator.addMethod('selectcountry', function (value) {
return (value != 'Nothing');
}, "Please Select a Country");
$.validator.addMethod("url", function(value, element)
{
return this.optional(element) || /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i.test(value);
}, "Please Enter A Valid Website URL");
});
</script>
PHP is below:
<?php
session_start();
if(strtolower($_REQUEST['answer']) == $_SESSION['captcha']){
echo 'true';die;
}else{
echo 'false';die;
}
?>
The validation still works onkeyup etc with and without remote but just not on submit?
The remote rule syntax is slightly off in your case
answer: {
required: true,
remote: {
url: "Captcha/check-captcha.php",
type: "POST",
data: {
captcha: function () {
return $("#answer").val();
}
}
}
}

kendo ui how to filter dataSource requestStart

Main Problem
My current problem is the refresh progress when updating a grid datasource. I have change my code use the kendo.ui.progress in that way when requestStart event starts I ser the kendo.ui.progress to true. This activates the loading image when it end it calls the requestEnd.
The problem is that this event is hapenning for sorting and filtering. And I want it to only trigger for the read function of the dataSource. This problem makes the grid to use the progress endlessly.
Is there some way to filter in the requestStart and requestEnd only activate on the transport read?
My DataSource Code
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: url_Obtener_Periodo,
type: "POST"
},
parameterMap: function (options, operation) {
if (operation == "read" && options) {
return {
"periodo.Year": $("#periodo-anio").val(),
"periodo.Month": $("#periodo-mes").val(),
"Filtro": $("#Filtro").val()
};
}
}
},
requestStart: function (e) {
kendo.ui.progress($("#grid-container"), true);
},
requestEnd: function (e) {
kendo.ui.progress($("#grid-container"), false);
},
schema:{
model: {
id: "Codigo_De_Pedido",
fields: {
Codigo_De_Pedido: { type: "number" },
Fecha_Y_Hora_De_Creacion: { type: "date" },
UserName: { type: "string" },
Nombre_Del_Usuario: { type: "string" },
Codigo_Del_Vendedor: { type: "number" },
Nombre_Del_Vendedor: { type: "string" },
Is_Pedido_Closed: { type: "bool" },
Estado: { type: "string" }
}
}
},
pageSize: 10
});
The changes I did to solve the progress endlessly problem where 2.
Removing requestEnd function from the dataSource
Adding dataBound function to the Grid
Data Source Code
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: url_Obtener_Periodo,
type: "POST"
},
parameterMap: function (options, operation) {
if (operation == "read" && options) {
return {
"periodo.Year": $("#periodo-anio").val(),
"periodo.Month": $("#periodo-mes").val(),
"Filtro": $("#Filtro").val()
};
}
}
},
schema:{
model: {
id: "Codigo_De_Pedido",
fields: {
Codigo_De_Pedido: { type: "number" },
Fecha_Y_Hora_De_Creacion: { type: "date" },
UserName: { type: "string" },
Nombre_Del_Usuario: { type: "string" },
Codigo_Del_Vendedor: { type: "number" },
Nombre_Del_Vendedor: { type: "string" },
Is_Pedido_Closed: { type: "bool" },
Estado: { type: "string" }
}
}
},
pageSize: 10,
requestStart: function (e) {
kendo.ui.progress($("#grid-container"), true);
}
});
Kendo Grid Code
kendoGrid = $("#selectable-pedidos").kendoGrid({
dataSource: dataSource,
pageable: true,
sortable: true,
filterable: {
extra: false,
operators: {
string: {
startswith: "Comienza Con",
eq: "Es Igual A",
neq: "No Es Igual A"
}
}
},
dataBound: function (e) {
kendo.ui.progress($("#grid-container"), false);
},
columns: [
{ field: "Fecha_Y_Hora_De_Creacion", title: "Fecha y Hora", template: "#= kendo.toString(Fecha_Y_Hora_De_Creacion, 'dd/MM/yyyy hh:mm:ss tt') #" },
{ field: "Codigo_De_Pedido", title: "Código de Pedido" },
{ field: "Estado", filterable: true, title: "Estado" },
{ field: "Codigo_Del_Vendedor", title: "Código de Vendedor" },
{ field: "Nombre_Del_Vendedor", title: "Nombre de Vendedor" },
{
command: {
text: "Ver Detalle de Pedido",
click: function (e) {
$("#empty").append("<form method='POST' action='/HojaDeRuta/GetById/'><input type='hidden' name='Codigo_Pedido' value='"
+ this.dataItem($(e.currentTarget).closest("tr")).Codigo_De_Pedido + "' /><input type='submit' /></form>");
$("#empty input[type='submit']").click();
}
},
title: " "
}
]
}).data("kendoGrid");
There are a few things about your questions worth mentioning for those who read this:
Is there some way to filter in the requestStart and requestEnd only
activate on the transport read?
Yes, but it will not help you. The parameter of the event has a type property that will contain read, update, destroy or create.
statementEntriesDS.bind("requestStart", function (e) {
switch (e.type) {
case "create":
alert('-> event, type "create".');
break;
case "read":
alert('-> event, type "read".');
break;
case "update":
alert('-> event, type "update".');
break;
case "destroy":
alert('-> event, type "destroy".');
break;
}
});
Your example code doesn't specify serverFiltering or serverSorting so sorting and filtering wouldn't cause an remote action. You'll only get client-side sorting and filtering. However, if they are specified they're all going to result in a read and that wouldn't really help you.
That you would not have the requestEnd event fire sounds odd. You should probably add a handler for the error event and see if something is failing.
If you really want complete control over what's happening, you can specify a function for your read:
transport: {
read: function (options) {
kendo.ui.progress($gridContainer, true);
$.ajax({
url: carrierServiceBaseUrl + "/GetManualStatementsCarrierList",
contentType: 'application/json; charset=utf-8',
dataType: "json",
type: "POST",
success: function (result) {
// notify the data source that the request succeeded
options.success(result);
kendo.ui.progress($gridContainer, false); },
error: function (result) {
options.error(result); // Call the DataSource's "error" method with the results
kendo.ui.progress($gridContainer, false);
notification.show({
title: "ERROR:",
message: result.statusText
}, "error");
}
});
}
}

Resources