Hi im looking for a way to submit a form that contains multiple tabbed forms. The user must be able to submit the entire data from all tabs at a single submit by POST. The major problem is that the data wont submit unless it is explicitly rendered / opened and when submitting it does not include the other un-rendered tab forms. :(
Ive been looking for ways but in futile. Correct me if im wrong is this something to do with data-binding?
Sample code:
var fp = new Ext.FormPanel({
renderTo: 'parti2',
fileUpload: true,
width: 866,
frame: true,
title: ' ',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 130,
waitMsgTarget: 'mm_loader',
defaults: {
anchor: '95%',
msgTarget: 'side'
},
{
/**** tab section ****/
xtype:'tabpanel',
plain:true,
activeTab: 0,
autoHeight:true,
defaults:{bodyStyle:'padding:10px'},
items:[{
/**** new tab section ****/
title:'Personal Details',
layout:'form',
defaults: {width: 230},
defaultType: 'textfield',
items:[{
xtype: 'textfield',
fieldLabel: 'First Name',
name: 'sec2_ab1',
},{
xtype: 'textfield',
fieldLabel: 'Middle Name',
name: 'sec2_ab2',
},{
xtype: 'textfield',
fieldLabel: 'Last Name',
name: 'sec2_ab3',
},{
xtype: 'textfield',
fieldLabel: 'Nationality',
name: 'sec2_ab4'
},{
xtype: 'textfield',
fieldLabel: 'Height',
name: 'sec2_ab13',
},{
xtype: 'textfield',
fieldLabel: 'Education',
name: 'sec2_ab15',
}]
},{
/**** new tab section ****/
layout:'form',
title: 'Contract info',
autoHeight:true,
defaults: {
anchor: '95%',
msgTarget: 'side'
},
defaultType: 'textfield',
items:[
{
xtype: 'textfield',
fieldLabel: 'Monthly Salary',
name: 'section_ab5',
},{
xtype: 'textfield',
fieldLabel: 'Work span',
name: 'section_ab4',
},{
xtype: 'fileuploadfield',
id: 'form-file',
fieldLabel: 'Photo',
allowBlank: true,
msgTarget: 'side',
name: 'anyfile1',
buttonCfg: {
text: '',
iconCls: 'upload-icon'
}
}]
},{
/**** new tab section ****/
title: 'Knowledge of Languages',
layout:'form',
autoHeight:true,
defaults: {
anchor: '95%',
msgTarget: 'side'
},
items:[combo_kl]
} ] /**** end tabs ****/
},{
html: ' ', autoHeight:true, border: false, height: 50, defaults: { anchor: '95%' }
}
,{
buttons: [{
text: 'Reset Form',
handler: function(){
fp.getForm().reset();
}
},{
text: 'Submit Form',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
method:'POST',
url: '?handler/save',
waitMsg: 'Please wait as the Resume is being Send...',
success: function(fp, o){
msg('Success', 'Processed file: "'+o.result.file+'" ');
},
fail: function(fp, o) {
msg('Fail', 'erronious');
}
});
}
}
}] // button end
}]
});
Try adding the following to your TabPanel declaration:
deferredRender: false
This tells the TabPanel to render all of it's child components immediately. Currently your TabPanel is only rendering visible components which is causing problems with the form submit.
Great! That worked perfectly fine now! Thanks! :)
I also found other way to submit the tab panel form's parameters, without deferredRer, altogether by adding:
params: fp.getForm().getFieldValues(true)
on the submit command. :)
fp.getForm().submit({
method: 'POST',
url: '?hander/save',
waitMsg: 'Please wait for the server response...',
params: fp.getForm().getFieldValues(true),
success: function (fp, o) {
msg('Success', 'Processed file: "' + o.result.file + '" ');
},
fail: function (fp, o) {
msg('Fail', 'erronious');
}
});
Related
I have simple kendo UI grid
$("#Grid").kendoGrid({
dataSource: {
serverPaging: true,
transport: {
read: "Course/Read",
dataType: "json"
},
schema: {
data: "Data",
total: "Total",
errors: "Errors"
},
pageSize: 10
},
pageable: true,
columns:
[
{ field: "CourseName", title: "Name", width: 100 },
{ field: "SpecialtyName", title: "Specialty", width: 100, filterable: false },
{ title: "Edit", template: '<span class="EditIcon"><i data-bind="click:Edit(#: Id#)" class="fa fa-edit"></i></span>', width: 50 },
]
});
the problem is when I am using:
data-bind="click:Edit(#: Id#)"
when click on edit calling function not work inside kendo grid notice that both the grid and function inside knockout viewmodel
function viewmodel() {
var self = this;
self.Load = function () {
$("#Grid").kendoGrid({
dataSource: {
type: "aspnetmvc-ajax",
serverPaging: true,
transport: {
read: "Course/Read",
dataType: "json"
},
schema: {
data: "Data",
total: "Total",
errors: "Errors"
},
pageSize: 10
},
pageable: true,
columns:
[
{ field: "CourseName", title: "Name", width: 100 },
{ field: "SpecialtyName", title: "Specialty", width: 100, filterable: false },
{ title: "Edit", template: '<span class="EditIcon"><i data-bind="click:Edit(#: Id#)" class="fa fa-edit"></i></span>', width: 50 },
]
});
}
self.Load();
self.Edit= function (Id) {
////////my code////////
}
}
everything work fine the binding retrieve data, extra except call knockout method inside kendo grid, appreciate any help thanks.
if anyone looking for answer or open this post, this is not related to kendo, this is because the grid render rows after knockout binding done, so you can take viewmodel object in temp var in javascript and use it like tempvar.callfunction().
it is kendoui grid working against webapi (.net mvc 4 project)
the kendoGrid part in my js file:
$("#eventsgrid").kendoGrid({
dataSource: {
transport: {
read: { url: "/Webapi/V2/.../events", type: "GET" },
update: { url: "/Webapi/V2/.../events", type: "PUT" },
create: { url: "/Webapi/V2/.../events", type: "POST" },
destroy: { url: "/Webapi/V2/.../events", type: "DELETE" }
},
pageSize: 10,
schema: {
model: {
id: "eventId",
fields: {
eventId: { type: "number", editable: false, nullable: true },
eventCode: { type: "string" },
eventLocation: { type: "string" },
clientId:{ type: "string" },
startDate:{ type: "date" },
endDate: { type: "date" }
}
}
}
},
columns: [
{ field: 'eventId', title: 'ID', width: '50px', filterable: true },
{ field: 'eventCode', title: 'Code', width: '80px', filterable: true },
{ field: 'eventLocation', title: 'Location', width: '150px', filterable: true },
{ field: 'clientId', title: 'Client', width: '80px', filterable: true },
{ field: 'startDate', title: 'Start', width: '80px', format: "{0:MM/dd/yyyy}", filterable: { ui: "datepicker" } },
{ field: 'endDate', title: 'End', width: '80px', format: "{0:MM/dd/yyyy}", filterable: { ui: "datepicker" } },
{ command: [{ id: "edit", name: "edit", text: "Edit" }, { id: "destroy", name: "destroy", text: "Delete", width: "30px" }, { text: 'Details', click: gotouser }], title: " ", width: "240px" }
],
sortable: true,
editable: "popup",
filterable: {
extra: false,
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
}
}
},
toolbar: [{ name: "create", text: "Add new Event" }],
pageable: { pageSizes: true | [10, 20, 30] }
});
the problem is: when i edit a record, or post a new one, the value i receive in my mvc controller for any of the date fields, is null.
when i check in my chrome tools, see what the grid sends to the controller (when you hit update in the popup), like this:
clientId: 1
startDate: Tue Jan 20 2015 00:00:00 GMT-0500 (Eastern Standard Time)
endDate: Thu Jan 22 2015 00:00:00 GMT-0500 (Eastern Standard Time)
logo: abcsd.jpg
featured: 4
obviously the date format is wrong, and i suppose that is why the controller does not see it as a date, the conversion/binding fails, and it gives me null.
How do i make it send a different format, like mm/dd/yyyy ? isn't that covered by the format definitions in the columns array?
You can try to use parameterMap function. Look at kendo parameterMap documentation.
Similar to this:
parameterMap: function (data, operation) {
if (operation != "read") {
var parsedDate = kendo.parseDate(data.startDate, "MM/dd/yyyy");;
data.startDate = parsedDate;
return data;
}
}
For kendo parsing dates look at kendo parseDate
in the parameterMap use:
var parsedDate = kendo.toString(data.startDate, "MM/dd/yyyy")
the kendo.parseDate function takes a string as a parameter
OK, I followed Dmitriy's line, and was able to make it work. so for future generations, here is what you need to add to your js:
update: {
url: "/Webapi/..../events",
dataType: "json",
type: "PUT",
data: function (data) {
data.startDate = kendo.toString(data.startDate, "yyyy-MM-dd");
data.endDate = kendo.toString(data.endDate, "yyyy-MM-dd");
// repeat for all your date fields
return data;
}
},
// same thing for your 'create'.
// Sorry, look like a bit of 'Repeat yourself', but at least it's working.
So again, big thanks to Dimitriy!
I have a Jqgrid, In my MVC view, there is no problem in displaying the data in the grid. But I want to apply the custom paging in the grid, so i have created the method in my controller which takes two parameters (pageNumber and rowSize) and returns the data based on the these two parameters.
Now my question is that how can i send these two property of grid to the controller and get the changes reflected on the grid.
Note: i also tried to send the value of rowSize using ajax on the button click but after executing the code in the server there is no changes in the grid(as i expected).
View:
<table id="jQGridDemo">
</table>
<div id="jQGridDemoPager">
</div>
<script type="text/javascript">
jQuery("#jQGridDemo").jqGrid({
datatype: "json",
colNames: ['Id', 'First Name', 'Last Name', 'Last 4 SSN', 'Department',
'Age', 'Salary', "Address", 'Marital Status'],
colModel: [
{ name: 'ID', index: '_id', width: 20, stype: 'text' },
{ name: 'FirstName', index: 'FirstName', width: 150 },
{ name: 'LastName', index: 'LastName', width: 150 },
{ name: 'LastSSN', index: 'LastSSN', width: 100 },
{ name: 'Department', index: 'Department', width: 80, align: "right" },
{ name: 'Age', index: 'Salary', width: 80, align: "right" },
{ name: 'Salary', index: 'Salary', width: 80, align: "right" },
{ name: 'Address', index: 'Address', width: 150, sortable: false },
{ name: 'MaritalStatus', index: 'MaritalStatus', width: 100, sortable: false }
],
rowNum: 10,
loadonce: false,
rowList: [5, 10, 20, 50],
pager: "#jQGridDemoPager",
height: "100%",
sortname: 'ID',
viewrecords: true,
sortorder: "desc",
caption: "List Employee Details",
url: '/Home/Records'
});
$(".ui-pg-input").click(function () {
alert(this.value);
$.ajax({
type: 'POST',
url: window.location + "Home/Records",
data: {
pageNumber: this.value
},
success: function (data) {
alert("ajax call completed");
},
error: function () {
alert("Something went Wrong");
}
});
})
</script>
Controller
public JsonResult Records(int pageNumber=3, int rowSize = 5)
{
// code for custom paging
return json;
}
JSON Returned from Server:
[{"ID":1,"FirstName":"Alan","LastName":"Donald","LastSSN":"123","Department":"Bowler","Age":"44 ","Salary":"1000000 ","Address":"South Africa","MaritalStatus":"Married ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":1}],"IsTemporary":false}},{"ID":2,"FirstName":"Donald","LastName":"Duck","LastSSN":"345","Department":"Actor","Age":"98 ","Salary":"2000000 ","Address":"USA","MaritalStatus":null,"EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":2}],"IsTemporary":false}},{"ID":3,"FirstName":"Virat","LastName":"Kohli","LastSSN":"111","Department":"Batsman","Age":"28 ","Salary":"1000000 ","Address":"India","MaritalStatus":"Unknown ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":3}],"IsTemporary":false}},{"ID":4,"FirstName":"MS","LastName":"Dhoni","LastSSN":"112","Department":"Captain","Age":"31 ","Salary":"9000000 ","Address":"India","MaritalStatus":"Married ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":4}],"IsTemporary":false}},{"ID":5,"FirstName":"Sachin","LastName":"Tendulkar","LastSSN":"113","Department":"Superman","Age":"40 ","Salary":"90000000 ","Address":"India","MaritalStatus":"Married ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":5}],"IsTemporary":false}},{"ID":6,"FirstName":"Virendra","LastName":"Sehwag","LastSSN":"114","Department":"Batsman","Age":"36 ","Salary":"8000000 ","Address":"India","MaritalStatus":"Married ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":6}],"IsTemporary":false}},{"ID":7,"FirstName":"Zaheer","LastName":"Khan","LastSSN":"115","Department":"Bowler","Age":"36 ","Salary":"3000000 ","Address":"India","MaritalStatus":"Married ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":7}],"IsTemporary":false}},{"ID":8,"FirstName":"Demo","LastName":"Demo","LastSSN":"Demo","Department":"Demo","Age":"Demo ","Salary":"Demo ","Address":"Demo","MaritalStatus":"Demo ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":8}],"IsTemporary":false}},{"ID":9,"FirstName":"Demo","LastName":"Demo","LastSSN":"Demo","Department":"Demo","Age":"Demo ","Salary":"Demo ","Address":"Demo","MaritalStatus":"Demo ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":9}],"IsTemporary":false}},{"ID":10,"FirstName":"Demo","LastName":"Demo","LastSSN":"Demo","Department":"Demo","Age":"Demo ","Salary":"Demo ","Address":"Demo","MaritalStatus":"Demo ","EntityState":2,"EntityKey":{"EntitySetName":"tbl_Details","EntityContainerName":"JQGridDBEntities","EntityKeyValues":[{"Key":"ID","Value":10}],"IsTemporary":false}}]
I think there are misunderstanding how jqGrid works. If you don't use loadonce: true option jqGrid send automatically request to url with additional parameters which specify the page size and the requested page. So you don't need to many any $.ajax and you don't need to bind $(".ui-pg-input").click. Default names of 1-based "page number" parameter is page and the name of "row size" parameter is rows. So you need just rename parameters of Records actions.
Alternatively you can use prmNames option of jqGrid (see the documentation) to inform jqGrid to use other parameter names as default page and rows. For example you can add the option
prmNames: {page: "pageNumber", rows: "rowSize"}
to solve your problem.
I have following setup. I have a view, in asp.net MVC, which loads without any data. On click of a button, we setup a jqgrid (call (#grid).jqGrid) which retrieves data from a server. But, we also want to send some parameters. These parameters will be used as filters on the server side before returning json data for jqgrid. How to do this?
`$('#getrecords').click(function (e) {
e.preventDefault();
debugger;
jQuery("#records").jqGrid({
url: '/Test/Data/',
datatype: 'json',
mtype: 'POST',
ajaxGridOptions: { contentType: "application/json" },
colNames: ['Id', 'Name'],
colModel: [
{ name: 'Id', index: 'Id', width: 50, align: 'left' },
{ name: 'Name', index: 'Name', width: 300, align: 'left'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [10, 20, 50],
viewrecords: true,
caption: 'My first grid',
postData: {
myname: function () { $('#myname').val(); },
childname: function () { $('#child').val(); }
}
});
});
`
You can use the grid's postData option to define parameters that should be passed to the server on each request:
postData: { param1: 'value1', param2: 'value2', etc... }
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
In my web application I have used EXT JS code.
Currently I am moving EXT JS code to jQuery code.
Below is my EXT JS code, it contains form panel statements:
var signInForm = new Ext.FormPanel({
renderTo: Ext.get('sign_In_Form'),
labelWidth: 125,
labelAlign: 'right',
frame: false,
border: false,
monitorValid: true,
defaults: {
width: 200
},
defaultType: 'textfield',
items: [{
fieldLabel: 'Email/Username',
name: 'username',
allowBlank: false
},{
fieldLabel: 'Password',
name: 'password',
inputType: 'password',
allowBlank: false
},{
name: 'test',
value: 'testuser',
xtype: 'hidden'
}
],
buttonAlign: 'left',
buttons: [{
text: 'Sign In',
formBind: true,
handler: function() {
if (processing == false) {
//some code here
}
}
}],
keys: {
key: Ext.EventObject.ENTER,
fn: function() { // some code here }
}
});
I want to convert above EXT JS code to jQuery code.
Is there any guide available to do this....?
Your pointers are really helpful.
Thanks,
Pravin
Raynos is right, you need to start reading the documentation to convert this code. Although it is not very hard to do.
If you are using EXT JS for a mobile app then you can use:
senchalabs / jQTouch