i am implementing project in extjs. i am very new to extjs. i had created view with two Textfields Question and Option and also created two buttons as ok and cancel.
My view code:
Ext.create('Ext.form.Panel', {
title: 'Question-option',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
name: 'Question',
fieldLabel: 'Question',
allowBlank: false // requires a non-empty value
}, {
xtype: 'textfield',
name: 'Option',
fieldLabel: 'Option',
vtype: 'Option' // requires value to be a valid email address format
},
{xtype: 'button', text: 'Ok'},
{xtype: 'button', text: 'Cancel'}
]
});
On ok button click i want to add these textfields data into store.
So can you please suggest me how to write buttonclick event to add all these textfields data into store.
Take this store as example:
Ext.define ('model', {
extend: 'Ext.data.Model' ,
fields: ['Question', 'Option']
});
var store = Ext.create ('Ext.data.Store', {
model: 'model'
});
// Handler called on button click event
function handler (button) {
var form = button.up('form').getForm ();
// Validate the form
if (form.isValid ()) {
var values = form.getFieldValues ();
store.add ({
Question: values.Question ,
Option: values.Option
});
}
else {} // do something else here
}
You get the form data and then add those data to the store.
Cyaz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With