PDA

View Full Version : Form (maybe store) send multiple json data after second time save button clicked



taujago
26 Aug 2012, 7:32 AM
Hi..
I have a problem with my input form. at the first time I click save button, json data is oke.




{"id":null,"id_old":"",
"id_rekening_apbd":"2P.3.3","nama_rekening":"",
"nama_anggaran":"fjdkfjdkf ","keterangan":"","tahun":"",
"id_rekening":"2P.3","nominal":"9000000"}





but when I click save button once again, json data like this. become double.




[{"id":null,"id_old":"","id_rekening_apbd":"2P.3.3",
"nama_rekening":"","nama_anggaran":"fjdkfjdkf ","keterangan":"","tahun":"",
"id_rekening":"2P.3","nominal":"9000000"},

{"id":null,"id_old":"","id_rekening_apbd":"2P.3.3",
"nama_rekening":"","nama_anggaran":"fjdkfjdkf ","keterangan":"","tahun":"","id_rekening":"2P.3",
"nominal":"9000000"}]





here is my code :

Data Model

Ext.define('apbd_GridModel', {
extend: 'Ext.data.Model',
fields: [

{name: 'id', type: 'id'},
{name: 'id_old', type: 'id_old'},
{name: 'id_rekening_apbd', type: 'id_rekening_apbd'},
{name: 'nama_rekening', type: 'nama_rekening'},
{name: 'nama_anggaran', type: 'nama_anggaran'},
{name: 'keterangan', type: 'keterangan'},
{name: 'tahun', type: 'tahun'},
{name: 'id_rekening', type: 'id_rekening'},
{name: 'nominal', type: 'nominal'}
],
idProperty : 'id'
});

Data Store :


var apbd_store = Ext.create('Ext.data.Store', {
groupField: 'nama_rekening',
// pageSize: itemsPerPage,
model: 'apbd_GridModel',
proxy: {
type: 'ajax',
api: {
create : base_url + 'apbd/save',
read : base_url + 'apbd/get_data',
update : base_url + 'apbd/update',
destroy : base_url + 'apbd/delete'
},
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy : 'POST'
},
reader: {
type: 'json',
root : 'results',
totalProperty: 'records',
successProperty: 'success',
messageProperty: 'message'


},
extraParams:{
action:'pagingTestGrid',sidx:'nama_rekening',sord:'asc'
},
writer: {
type : 'json',
writeAllFields : true,
root : 'data',
encode : true
},



listeners: {

exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'ERROR',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});

//apbd_rowedit.startEdit(0, 0);
}
}
} ,
autoLoad: true

});


And form :



var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';

var simple = Ext.widget({
xtype: 'form',
layout: 'form',
height : 200,
collapsible: true,
id: 'simpleForm',
frame: true,
title: '',
bodyPadding: '5 5 0',
width: 480,
fieldDefaults: {
msgTarget: 'side',
labelWidth: 100
},
defaultType: 'textfield',
items: [
combo = Ext.create('Ext.form.ComboBox', {

fieldLabel: 'Jenis rekening',
name : 'id_rekening',
xtype : 'combo',
emptyText : 'Pilih Rekening',
store : store_combo_search,
displayField : 'nama_rekening',
valueField : 'id_rekening',
queryMode : 'remote',
width : '200px',
columnWidth : '300px',
listeners : {
select : function (combo,record) {
//id_rekening = this.getValue();
console.log(this.getValue());
if(!new_record) {
Ext.getCmp('id_rekening_apbd').setValue( this.getValue());
}
}
}


}),
{
fieldLabel : 'Kode Rekening',
afterLabelTextTpl : required,
name : 'id_rekening_apbd',
id : 'id_rekening_apbd',
allowBlank : false
},
{
fieldLabel : 'Uraian',
afterLabelTextTpl : required,
name : 'nama_anggaran',
allowBlank : false
},
{
fieldLabel : 'Jumlah',
afterLabelTextTpl : required,
name : 'nominal',
allowBlank : false
//,
//xtype: numberfield
},
{
fieldLabel : 'Keterangan',

name : 'keterangan',
allowBlank : true
},

],

buttons: [{
text: 'Simpan',
iconCls : 'icon-save',
handler: function() {
var form = this.up('form').getForm();
if(!new_record) {
if(form.isValid()) {
// console.log(form.getValues());
apbd_store.insert(0, form.getValues()) ;
apbd_store.sync();
//apbd_store.load();
data_change = 1;
//S simple.getForm().reset();
//this.reset();
//apbd_store.load();
//this.close();
}
}
}
},{
text: 'Reset',
iconCls : 'icon-reset',
handler: function() {
this.up('form').getForm().reset();
}
}, {
text: 'Tutup',
iconCls : 'icon-close',
handler: function() {
//this.up('form').getForm().close();
//this.reset();
form_win.close();
simple.reset();

}
}
]
});



but when I close form window, re-load store and show form window again, it's just OKE. I'm confuse why json row is increasing. and back to normal after close form window and re-show the window. been spent all day long for this issue. hope someone can help me. sorry. I'm beginner. just start 3 days ago in senca Extjs.

scottmartin
27 Aug 2012, 12:50 PM
What is your response from the server .. are you sending success: true?

Scott

taujago
27 Aug 2012, 9:07 PM
do you mean the fist attempt ?yes. I sent success : true.
but for next attempt, success : false . because insert query is failed.

insert query at the second attempt like this


insert into table (0,1) values (array,array)

third attempt will be
insert into table (0,1,2) values (array,array,array)