Below is the code for creating a simple form. It is not working. Any solutions?
Sample form
Nothing is showing when I run this code.
Ext.onReady(function(){
Ext.QuickTips.init();
var simple=new Ext.FormPanel({
lableWidth:75,
frame:true,
url:'save-form.php',
title:'Login',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults:{width: 230},
defaultType:'textfield',
xtype: 'fieldset',
items:[
{
fieldLabel: 'username',
name:'Username',
id:'user',
allowBlank:false
},
{
fieldLabel:'password',
name:'Password',
id:'pass',
allowBlank:false,
inputType:'password'
},
{
xtype:'combobox',
store: Ext.create('Ext.data.Store',
{
fields:['abbr','name'],
data:[
{
'abbr':'dev',
'name':'Developer'
},
{
'abbr':'test',
'name':'tester'
}]
}),
displayField:'name',
emptyText:'Select user type..'
},
{
fieldLabel:'Email',
name:'Email',
allowBlank:false,
vtype:'email'
},
{
boxLabel:'Remember me',
xtype:'checkbox'
}],
buttons:[
{
text:'Login',
handler:function()
{
var a=Ext.getCmp('user').getValue();
var b=Ext.getCmp('pass').getValue();
if(a=="saturn"&&b=="saturn")
alert('Succesfull');
else
alert('id and password missmatch');
simple.getForm().reset();
}
}]
})
simple.render(document.body);
});
HTML:
<html>
<head>
<title>Login</title>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"></script>
<script type="text/javascript" src="login.js"></script>
</head>
</html>
You have used fieldset in form directly if you want to use this then add inside items of form. Please refer ExtJs Docs
I have created an demo hope it will help you. Sencha Fiddle
Ext.create('Ext.form.Panel', {
title: 'Simple Form',
renderTo: Ext.getBody(),
lableWidth: 75,
frame: true,
url: 'save-form.php',
bodyStyle: 'padding:5px 5px 0',
width: '80%',
items: [{
xtype: 'fieldset',
padding: 20,
defaults: {
width: '100%',
flex: 1
},
defaultType: 'textfield',
items: [{
fieldLabel: 'username',
name: 'Username',
id: 'user',
allowBlank: false
}, {
fieldLabel: 'password',
name: 'Password',
id: 'pass',
allowBlank: false,
inputType: 'password'
}, {
xtype: 'combobox',
store: Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
'abbr': 'dev',
'name': 'Developer'
}, {
'abbr': 'test',
'name': 'tester'
}]
}),
displayField: 'name',
emptyText: 'Select user type..'
}, {
fieldLabel: 'Email',
name: 'Email',
allowBlank: false,
vtype: 'email'
}, {
boxLabel: 'Remember me',
xtype: 'checkbox'
}],
}],
buttons: [{
text: 'Login',
formBind: true,
handler: function () {
//your login here
Ext.Msg.alert('Success','You have clicked on Login...!');
}
}]
});
Related
I am having the form and grid panel. Form receive some data and after clicking on add button on the form , the data should go to grid panel means it will added into grid. I have some code but not working.
Ext.onReady(function() {
var addUserData = [
{
Utype: "Admin",
Uname: "Jacob",
Uemail : "adminjacob#gmail.com",
},];
Ext.define('AddUsersModel', {
extend: 'Ext.data.Model',
fields: ['Utype', 'Uname', 'Uemail']
});
var addUserStore = Ext.create('Ext.data.Store', {
data : addUserData,
model : 'AddUsersModel'
});
var added_users = Ext.create('Ext.grid.Panel', {
id:'addUsersID',
store: addUserStore,
border:0,
columns:
[ {
text : '<span class="cb_head">Type</span>',
dataIndex: 'Utype',
flex : 1,
},{
text: '<span class="cb_head">Name</span>',
dataIndex: 'Uname',
flex : 1,
},{
text: '<span class="cb_head">Email</span>',
dataIndex: 'Uemail',
flex : 1,
}
],
stateId: "added_users_state_id",
stateful: true,
stateEvents: ['columnresize', 'columnmove', 'show', 'hide' ],
});
added_users.render('added_users');
var empType = Ext.create('Ext.data.ArrayStore', {
fields: ['searchopt'],
data : [['Admin'],['Trader']],
id:'CUSTOMERitems',
});
var add_user = Ext.create('Ext.form.Panel', {
bodyPadding: 5,
id:'addUserID',
defaultType: 'textfield',
items: [{
xtype: 'combobox',
fieldLabel: 'Employee Type',
emptyText : 'Select type',
id:'emptype',
name: 'type',
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
selectOnFocus:true,
store: empType,
queryMode: 'local',
displayField: 'searchopt',
valueField: 'searchopt',
listeners: {
beforequery: function (record) {
record.query = new RegExp(record.query, 'i');
record.forceAll = true;
}
}
},{
fieldLabel: 'Name',
emptyText : 'Name',
name: 'name',
allowBlank: false
},{
fieldLabel: 'Email',
name: 'email',
emptyText : 'Email',
allowBlank: false,
width:170,
},{
fieldLabel: 'City',
emptyText : 'City',
name: 'city',
allowBlank: false
},{
fieldLabel: 'Zip',
emptyText : 'Zip',
name: 'zip',
allowBlank: false
},
],
buttons: [ {
text: 'Add',
handler: function(form,grid,store) {
}
}],
});
add_user.render('add_user');
});
Can anyone help me out?
Kind Regards,
May be you can try setting the value of autoLoad to true
var addUserStore = Ext.create('Ext.data.Store', {
data : addUserData,
model : 'AddUsersModel',
autoLoad: true
});
i have a abstract form, that describes any basics fields. My idea, is that the form is shown with 3 columns layout.
So, i write:
Ext.define('AM.view.forms.UsuarioBase',{
extend: 'Ext.form.Panel',
bodyPadding: '5px 5px 5px 5px',
bodyStyle: 'border: none',
fieldDefaults: {
labelWidth: 65,
labelAlign: 'top'
},
initComponent: function(){
this.infoPersonal = [ anyFields ];
this.infoCuenta = [ anotherFields ];
this.infoContacto = [
{ fieldLabel: 'Tel Casa', name: 'Contacto-2', allowBlank: true},
{ fieldLabel: 'Tel Movil', name: 'Contacto-3', allowBlank: true},
{ fieldLabel: 'Tel Trabajo', name: 'Contacto-1', allowBlank: true},
{ fieldLabel: 'Tel Otro', name: 'Contacto-4', allowBlank: true},
{ fieldLabel: 'E-mail', name: 'Email', allowBlank: true},
{ fieldLabel: 'Domicilio', name: 'Domusuario', allowBlank: true}
];
this.items = [{
bodyStyle: 'border: none',
layout: 'column',
items: []
}];
this.callParent(arguments);
}
});
The fields, are in variables, because in the subclass i can add/remove/edit one or more fields.
So, in the subclass i do:
initComponent: function(){
this.callParent(arguments);
// Columnas
var primeraCol = {defaultType: 'textfield', style:'margin-left: 2px',items: this.infoPersonal};
var segundaCol = {defaultType: 'textfield', style:'margin-left: 2px',items: this.infoContacto};
var terceraCol = {defaultType: 'textfield', style:'margin-left: 2px',items: this.infoCuenta};
this.add(primeraCol);
this.add(segundaCol);
this.add(terceraCol);
}
The form is displayed with the correct fields in the columns. But, the columns not show inline, else, one below the other.
Any ideas ?.
The items in your column layout need to have either width (a value in pixels) or columnWidth (a ratio) specified. For example, to have three columns of equal width:
var primeraCol = {columnWidth: 0.333, defaultType: 'textfield', style:'margin-left: 2px',items: this.infoPersonal};
var segundaCol = {columnWidth: 0.333, defaultType: 'textfield', style:'margin-left: 2px',items: this.infoContacto};
var terceraCol = {columnWidth: 0.333, defaultType: 'textfield', style:'margin-left: 2px',items: this.infoCuenta};
I have created an application designed in Spring MVC3, Hibernate and Ext Js. It's a books library. I use Eclipse IDE.
In the WebContent folder i created the extjs application named app , there I uploaded extjs files too.
My application contains 4 packages: controller, model, store and view.
Controller Books.js:
Ext.define('ExtJS.controller.Books', {
extend: 'Ext.app.Controller',
stores: ['Books'],
models: ['Book'],
views: ['book.Edit', 'book.List'],
refs: [{
ref: 'booksPanel',
selector: 'panel'
},{
ref: 'booklist',
selector: 'booklist'
}
],
init: function() {
this.control({
'booklist dataview': {
itemdblclick: this.editUser
},
'booklist button[action=add]': {
click: this.editUser
},
'booklist button[action=delete]': {
click: this.deleteUser
},
'bookedit button[action=save]': {
click: this.updateUser
}
});
},
editUser: function(grid, record) {
var edit = Ext.create('ExtJS.view.book.Edit').show();
if(record){
edit.down('form').loadRecord(record);
}
},
updateUser: function(button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
if (values.id > 0){
record.set(values);
} else{
record = Ext.create('ExtJS.model.Book');
record.set(values);
record.setId(0);
this.getBooksStore().add(record);
}
win.close();
this.getBooksStore().sync();
},
deleteUser: function(button) {
var grid = this.getBooklist(),
record = grid.getSelectionModel().getSelection(),
store = this.getBooksStore();
store.remove(record);
this.getBooksStore().sync();
}
});
Model Book.js:
Ext.define('ExtJS.model.Book', {
extend: 'Ext.data.Model',
fields: ['id', 'title', 'author', 'publisher', 'isbn', 'pages', 'category', 'qty']
});
Store Books.js:
Ext.define('ExtJS.store.Books', {
extend: 'Ext.data.Store',
model: 'ExtJS.model.Book',
autoLoad: true,
pageSize: 35,
autoLoad: {start: 0, limit: 35},
proxy: {
type: 'ajax',
api: {
read : 'books/view.action',
create : 'books/create.action',
update: 'books/update.action',
destroy: 'books/delete.action'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true,
encode: false,
root: 'data'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});
View contains the Viewport.js:
Ext.define('ExtJS.view.Viewport', {
extend: 'Ext.container.Viewport'
});
and a folder named book where I have:
List.js:
Ext.define('ExtJS.view.book.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.booklist',
//requires: ['Ext.toolbar.Paging'],
iconCls: 'icon-grid',
title : 'Books',
store: 'Books',
columns: [{
header: "Title",
width: 50,
flex:1,
dataIndex: 'title'
},{
header: "Author",
width: 50,
flex:1,
dataIndex: 'author'
},{
header: "Publisher",
width: 50,
flex:1,
dataIndex: 'publisher'
},{
header: "Isbn",
width: 50,
flex:1,
dataIndex: 'isbn'
},{
header: "Pages",
width: 50,
flex:1,
dataIndex: 'pages'
},{
header: "Category",
width: 50,
flex:1,
dataIndex: 'category'
},{
header: "Qty",
width: 50,
flex:1,
dataIndex: 'qty'
}],
initComponent: function() {
this.dockedItems = [{
xtype: 'toolbar',
items: [{
iconCls: 'icon-save',
itemId: 'add',
text: 'Add',
action: 'add'
},{
iconCls: 'icon-delete',
text: 'Delete',
action: 'delete'
}]
},
{
xtype: 'pagingtoolbar',
dock:'top',
store: 'Books',
displayInfo: true,
displayMsg: 'Displaying books {0} - {1} of {2}',
emptyMsg: "No books to display"
}];
this.callParent(arguments);
}
});
and
Edit.js:
Ext.define('ExtJS.view.book.Edit', {
extend: 'Ext.window.Window',
alias : 'widget.bookedit',
requires: ['Ext.form.Panel','Ext.form.field.Text'],
title : 'Edit Book',
layout: 'fit',
autoShow: true,
width: 280,
iconCls: 'icon-user',
initComponent: function() {
this.items = [
{
xtype: 'form',
padding: '5 5 0 5',
border: false,
style: 'background-color: #fff;',
fieldDefaults: {
anchor: '100%',
labelAlign: 'left',
allowBlank: false,
combineErrors: true,
msgTarget: 'side'
},
items: [
{
xtype: 'textfield',
name : 'id',
fieldLabel: 'id',
hidden:true
},
{
xtype: 'textfield',
name : 'title',
fieldLabel: 'Title'
},
{
xtype: 'textfield',
name : 'author',
fieldLabel: 'Author'
},
{
xtype: 'textfield',
name : 'publisher',
fieldLabel: 'Publisher'
},
{
xtype: 'textfield',
name : 'isbn',
fieldLabel: 'Isbn'
},
{
xtype: 'textfield',
name : 'pages',
fieldLabel: 'Pages'
},
{
xtype: 'textfield',
name : 'category',
fieldLabel: 'Category'
},
{
xtype: 'textfield',
name : 'qty',
fieldLabel: 'Qty'
}
]
}
];
this.dockedItems = [{
xtype: 'toolbar',
dock: 'bottom',
id:'buttons',
ui: 'footer',
items: ['->', {
iconCls: 'icon-save',
itemId: 'save',
text: 'Save',
action: 'save'
},{
iconCls: 'icon-reset',
text: 'Cancel',
scope: this,
handler: this.close
}]
}];
this.callParent(arguments);
}
});
My app.js:
Ext.application({
name: 'ExtJS',
controllers: [
'Books'
],
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [
{
xtype: 'booklist'
}
]
});
}
});
The error "Remote exception" from store/Books.js is thrown. I don't know what can be the problem.
EDIT:
The problem is: "Error retrieving books from database". It comes from Java Controller:
#Controller
public class BookController {
private BookService bookService;
#RequestMapping(value="/books/view.action")
public #ResponseBody Map<String,? extends Object> view(#RequestParam int start, #RequestParam int limit) throws Exception {
try{
List<Book> books = bookService.getBookList(start,limit);
int total = bookService.getTotalBooks();
return ExtJSReturn.mapOK(books, total);
} catch (Exception e) {
return ExtJSReturn.mapError("Error retrieving books from database.");
}
}
See also BookService.java method:
#Transactional(readOnly=true)
public List<Book> getBookList(int start, int limit){
return bookDAO.getBooks(start, limit);
}
public int getTotalBooks(){
return bookDAO.getTotalBooks();
}
See BookDAO.java methods:
#SuppressWarnings("unchecked")
public List<Book> getBooks(int start, int limit) {
DetachedCriteria criteria = DetachedCriteria.forClass(Book.class);
return hibernateTemplate.findByCriteria(criteria, start, limit);
}
public int getTotalBooks(){
return DataAccessUtils.intResult(hibernateTemplate.find("SELECT COUNT(*) FROM books"));
}
Any idea?
Here is the problem:
org.springframework.orm.hibernate3.HibernateQueryException: books is not mapped [SELECT COUNT(*) FROM books]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: books is not mapped [SELECT COUNT(*) FROM books]
Fixed here: https://stackoverflow.com/a/14447201/1564840
This is my view
Ext.define("TimeSheet.view.Tracktime", {
extend: "Ext.form.Panel",
requires: ["Ext.form.FieldSet", "Ext.field.Text", "Ext.Button","Ext.Label", "Ext.field.Email", "Ext.field.Password","Ext.MessageBox", "Ext.Img"],
alias: "widget.tracktimeview",
config:{
id: 'entrypage',
fullscreen: true,
url: 'timesheet.ajatus.in/check.php',
//standardSubmit: false,
method: 'GET',
layout: {
centered: true,
},
defaults: {
styleHtmlContent: true,
//cls: 'backfield'
},
cls: 'panelBackground',
items: [{
xtype: 'fieldset',
id: 'loginfield',
autoComplete: true,
scrollable: false,
cls: 'formfield',
items: [{
xtype: 'image',
src: 'tracktime.png',
height: '60px',
cls: 'track'
},
{
xtype: 'textfield',
name : 'name',
label: 'tracktime/'
},
{
xtype: 'textfield',
name : 'uname',
allowBlank:false,
placeHolder: "User name"
},
{
xtype: 'passwordfield',
name : 'password',
allowBlank:false,
placeHolder: 'Password'
}
]
},{
xtype: 'button',
id: 'loginbtn',
cls: 'enter',
text: 'Sign in',
ui: 'confirm',
height: "50px",
}],
control: ({
'#loginbtn': {
tap: function() {
}
}
}),
},});
THIS IS CONTROLLER
Ext.define("TimeSheet.controller.Track", {
extend: "Ext.app.Controller",
config: {
refs: {
trackTimeView: "tracktimeview",
selector: '#tracktimeview',
addentryView: "addentryview",
selector: '#addentryview',
entryPage: '#entrypage',
loginBtn: '#loginbtn'
},
control:{
loginBtn: {
tap: "onLoginBtn"
},
onloginbtn: {
tap: function(btn) {
var form = Ext.getCmp('entry');
//var values = entry.getValues();
entry.submit({
method:'POST',
url: 'xxxxxxxx/check.php',
params: values,
success: function(response){
var text = response.responseText;
Ext.Msg.alert('Success', text);
},
failure : function(response) {
Ext.Msg.alert('Error','Error while submitting the form');
console.log(response.responseText);
}
});
}
},
}
},
onLoginBtn: function() {
console.log("onLoginBtn");
var values = TimeSheet.views.tracktimeview.entrypage.getValues();
TryLogin(values['uname'], values['password']);
},
launch: function () {
this.callParent(arguments);
console.log("launch");
},
init: function () {
this.callParent(arguments);
console.log("init");
}});
I have several tabs on toolbar each of them having seperate handler , i have called seperate function of each handler . The code is as below
Ext.define('myco.view.User', {
extend: 'Ext.Container',
config: {
scrollable: true,
items: [{
xtype: 'panel',
id: 'User'
},
{
docked: 'top',
xtype: 'toolbar',
items: [{
text: 'My Profile',
handler: function() {
var panel = Ext.getCmp('User'),
tpl = new Ext.XTemplate([
'<div class="demo-weather">',
'<tpl for=".">',
'<div class="day">',
'<div class="date">{username}</div>',
'<tpl for="weatherIconUrl">',
'<img src="{value}">',
'</tpl>',
'<span class="temp">{tempMaxF}°<span class="temp_low">{tempMinF}°</span></span>',
'</div>',
'</tpl>',
'</div>'
]);
panel.getParent().setMasked({
xtype: 'loadmask',
message: 'Loading...'
});
Ext.Ajax.request({
url: 'http://localhost:8000/api/myapp/user/',
method:'GET',
callbackKey: 'callback',
defaultHeaders : 'application/json',
params: {
//key: '23f6a0ab24185952101705',
//q: '94301', // Palo Alto
format: 'json',
//num_of_days: 5
},
success : function(response, opt) {
dataarray = Ext.decode(response.responseText);
weather=dataarray.objects;
panel.updateHtml(tpl.applyTemplate(weather))
panel.getParent().unmask();
},
failure : function(response, opt) {
Ext.Msg.alert('Failed', response.responseText);
panel.getParent().unmask();
}
});
}
},
{
text:'login',
handler: function() {
var main = new Ext.Panel({
title: 'My first panel', //panel's title
fullscreen: true,
//the element where the panel is going to be inserted
//html: 'Nothing important just dummy text' //panel's content
items:[
{
xtype: 'fieldset',
title: 'Login',
items: [
{
xtype: 'textfield',
label: 'Username',
name: 'username',
id : 'username'
},
{
xtype: 'passwordfield',
label: 'Password',
name: 'password',
id : 'password'
}
]
},
{
xtype: 'button',
text: 'Send',
ui: 'confirm',
handler: function() {}
}
]
});
panel.add(main);
alert('test');
}
}
]
}]
}
});
Now when i click on the tab , previous panel will not be cleared and data will get overlapped there ..... like when i click My profile profile is listed there , after that when i click login profile+ login both will be loaded one overlapping another ...
You should use Ext.tab.Panel for this, define your profile and login panels as items of a parent TabPanel, the switching will be handled by ExtJS. You can use the activate event of a Panel to add custom logic to execute when your tabs get activated.