Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert values in store in extjs

Tags:

extjs4.1

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.

like image 293
Shilpa Kirad Avatar asked Oct 31 '12 10:10

Shilpa Kirad


1 Answers

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

like image 93
Wilk Avatar answered Nov 01 '22 07:11

Wilk