How can I create dynamic form where all the fields are coming from a json file in sencha touch?
(Additional details transferred from "answer")
My json looks like it
{
success: true,
data: [
{xtype: "textfield", title: "label1", name: "textfield1"},
{xtype: "emailfield", title: "label2", name: "textfield2"},
{xtype: "passwordfield", title: "label3", name: "textfield3"},
{xtype: "button", title: "button", name: "button"}
]
}
I want a sepearte controller and a view.
i did it in a single controller file like this
form = Ext.create('MyApp.view.MyDataView');
var test=this;
var ajax = Ext.Ajax.request({
url: 'contacts.json',
method: 'get',
success: function(response)
{
console.log(response);
response = Ext.JSON.decode(response.responseText);
this.hello=response;
console.log(response.data.length);
for (var i = 0; i < response.data.length; i++)
{
form.add({
xtype: response.data[i].xtype,
id:response.data[i].title,
action:response.data[i].title,
label: response.data[i].title,
name: response.data[i].name
});
}
console.log(form.getValues());
form.setLayout();
form.show(document.body);
Ext.Viewport.animateActiveItem(form,{type: 'flip', direction: 'right'});
}
there is some problem i m facing regarding the utton tap event and if multiple buttons are there giving event to them is not yet possible for me ....can anybody help me regarding this ..
Have you tried something yet?
You can just create the form in the file like something like this:
{
xtype: 'form',
items: [ //...
]
}
Then you can load your file in, and decode it into a variable.
Ext.Ajax.request({
url: 'yourform.json',
success: function(response){
var formInJson = response.responseText;
var form = Ext.JSON.decode(formInJson);
//... do something with your form
}
});
Related
need your help on the following problem. I have an Extjs application, and I need to get some data from database at the begining of all, I mean, before everything loads (mostly views). This is because this data I need to load will be used to create a form in a specific view.
So the question is: where should I put the function that gets the data and stores it in a global variable? I tried to put that function in launch function on app.js, but the behavior is weird (sometimes loads the data before the view renders, and sometimes does it after).
Please see above the code:
Function that gets the data (placed in App.js and invoked inside launch function):
cargarItemsEvaluacion: function()
{
AppGlobals.itemsCargarFormEvaluacion = [];
Ext.Ajax.request(
{
url : 'app/proxy.evaluacion.php',
method: 'GET',
params :{
act: 'getEvalItemsForm'
},
success : function(response)
{
var obj = Ext.decode(response.responseText);
Ext.each(obj.results, function(item)
{
//console.log(item);
var tempItem = {
xtype: 'container',
layout: 'anchor',
flex: 1,
items: [
{
//xtype: 'fieldset',
title: item.nombre,
items: [
{
id: 'item_'+item.id,
xtype: 'textfield',
fieldLabel: item.descripcion,
name: 'item_'+item.id,
allowBlank: false,
blankText: 'Este campo es obligatorio',
maskRe: /^[0-9]{1}/,
maxLenght: 2,
validateOnChange: 'true',
emptyText: 'Nota (1 al 10)',
submitEmptyText: false,
validator: function(value)
{
if(value.length>2 || value>10)
{
return 'Complete con nota del 1 al 10';
}
var stringPad=/^[1-9]{1}[0-9]{0,1}/;
if (!stringPad.test(value))
{
return 'Complete con nota del 1 al 10';
}
else
{
return true;
}
}
}]
}]
};
AppGlobals.itemsCargarFormEvaluacion.push(tempItem);
});//End Ext.each
if(AppGlobals.itemsCargarFormEvaluacion.length>0)
{
var itemObservacion = {
xtype: 'container',
layout: 'anchor',
flex: 1,
items: [
{
title: 'Observaciones',
items: [
/*{
id: 'ascenso',
xtype: 'checkbox',
boxLabel: 'Recomienda ascenso',
name: 'ascenso'
},*/
{
id: 'observaciones',
xtype: 'textareafield',
grow: true,
fieldLabel: 'Agregue observaciones adicionales si lo cree necesario',
name: 'observaciones',
labelAlign: 'top'
}
]
}]
};
AppGlobals.itemsCargarFormEvaluacion.push(itemObservacion);
}
console.log(AppGlobals.itemsCargarFormEvaluacion);
},
failure: function(response)
{
var obj = Ext.decode(response.responseText);
console.log("Entra al failure "+response.responseText);
//Ext.example.msg("Error", "No se pudo comprobar si es posible cargar al evaluador. Error: "+obj.error);
}
});//End Ext.ajax
}
And this is the initComponent function on the view where I need to generate the form using the data I got from the previous function:
initComponent: function(){
var formEvaluacion = this.items[0];
if(AppGlobals.itemsCargarFormEvaluacion.length==0)
{
console.log("Data still no loaded");
}
else
{
console.log("Data loaded!");
}
console.log(AppGlobals.itemsCargarFormEvaluacion);
Ext.apply(formEvaluacion,{items: AppGlobals.itemsCargarFormEvaluacion});
this.callParent(arguments);
}
As you can see, I check if the data loads before the view renders, or after. And sometimes does it before, sometimes after...I don't know what it depends on...
Any help will be appreciated.
Mauro
Think I found the solution. I placed cargarItemsEvaluacion function into init function on app.js. Seem to be working so far.
Thanks!
Hello I have a window with tools. I have the tool: 'help', and when clicking on it I want it to output a tooltip with text from my HTML file, but actually it shows alert('Help'), and it doesn't output from the file:
tools: [
{
type: 'refresh',
name: 'refresh',
tooltip: 'reload'
},
{
type: 'help',
handler: function (event, toolEl, panel) {
alert('Help');
var tooltips = [{
target: 'tip1',
html: 'A very simple tooltip'
}, {
target: 'ajax-tip',
width: 200,
autoLoad: {url: '/help/note/help.html'},
dismissDelay: 15000 // auto hide after 15 seconds
},
];
Ext.each(tooltips, function (config) {
Ext.create('Ext.tip.ToolTip', config);
});
},
}
]
This picture shows what I actually want:
You need to load the html file in an Ajay request from server and then create the tooltip in the success callback.
Ext.Ajax.request({
url: '/help/note/help.html',
success: function(response){
// in the success callback you get the html text in the response.responseText
// and then you can create a tooltip with the content of it
}
});
So you can do the following in the callback
var html = response.responseText;
var tooltip = {
target: 'ajax-tip',
width: 200,
html: html,
dismissDelay: 15000 // auto hide after 15 seconds
};
The full code should be
{
type: 'help',
handler: function (event, toolEl, panel) {
Ext.Ajax.request({
url: '/help/note/help.html',
success: function (response) {
var html = response.responseText;
var tooltip = {
target: 'ajax-tip',
width: 200,
html: html,
dismissDelay: 15000 // auto hide after 15 seconds
};
Ext.create('Ext.tip.ToolTip', tooltip);
}
});
}
}
I checked out some other questions posted previously but couldn't find a relevant answer. So here I am posting again: Here's my code:
Ext.create('Rally.data.WsapiDataStore',{
autoLoad: true,
model: 'HierarchicalRequirement',
limit: '500',
fetch: ['ObjectID','DirectChildrenCount','FormattedID'],
filters:[{property: 'DirectChildrenCount', operator: '=', value: 0}], //tried both "0",'0'
listeners: {
load: function(store,data,success){
var data_length = data.length;
console.log("Number = ", data);
}
}
});
Result is an empty array. Furthermore, the result did not contain the field "DirectChildrenCount" at all, even though I am fetching it.
I tried your code without any changes, and it returned 300+ items. DirectChildrenCount was included in the result. It was tested against "2.0rc2" and "2.0rc1" with the same result. Here is screenshot from Chrome's DevTools:
Here is another short app where a grid of stories updated since yesterday is built, filtered by the same condition.
{property: 'DirectChildrenCount', operator: '=', value: 0}
js file is below:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
var millisecondsInDay = 86400000;
var currentDate = new Date();
var startDate = new Date(currentDate - millisecondsInDay);
var startDateUTC = startDate.toISOString();
Rally.data.ModelFactory.getModel({
type: 'UserStory',
success: function(model) {
this.grid = this.add({
xtype: 'rallygrid',
itemId: 'grid',
model: model,
columnCfgs: [
'FormattedID',
'Name',
'Owner',
'LastUpdateDate'
],
storeConfig: {
filters: [
{
property: 'LastUpdateDate',
operator: '>',
value: startDateUTC
},
{
property: 'DirectChildrenCount',
operator: '=',
value: 0
},
]
}
});
},
scope: this
});
console.log('items updated since', startDateUTC);
}
});
I need to display report in Grid / Table in Sencha Touch 2.3.0. Is there any build in function to do so.
The store needs to populate data from a REST webservice call.
For loading data you can use Ext.data.Store configured with REST proxy Ext.data.proxy.Rest
For displaying data from store you can use Ext.grid.Grid of Ext.dataview.DataView
I do this all the time with something like this:
(Though I haven't worked with the Grid, I'm quite sure the same principles apply...)
Ext.define('App.controller.GridController', {
extend : 'Ext.app.Controller',
config: {
refs: {
getApiButton: 'button[action=getApiData]'
},
control: {
'getApiButton' : {
tap : 'onButtonTap'
}
}
},
onButtonTap : function(field, value) {
var that = this;
Ext.Ajax.request({
url : someWebServiceUrl,
method: 'GET',
success: function (result, request) {
var res = Ext.decode(result.responseText);
if (res.success === true && res.data != false) {
var recipient = {
name: res.data[0].displayname,
picId: res.data[0].pictureid,
gender: res.data[0].gender
};
var mod = Ext.define('App.model.GradingPopModel', {
extend: 'Ext.data.Model',
config: {
fields: [
'name',
'picId',
'gender'
]
}
});
/* == this is probably where you want to make your changes to apply the model to the grid template
the sencha website has this:
data: {'items': [
{ 'name': 'Lisa', "email":"lisa#simpsons.com", "phone":"555-111-1224" },
{ 'name': 'Bart', "email":"bart#simpsons.com", "phone":"555-222-1234" },
{ 'name': 'Homer', "email":"home#simpsons.com", "phone":"555-222-1244" },
{ 'name': 'Marge', "email":"marge#simpsons.com", "phone":"555-222-1254" }
]}
*/
var store = Ext.create('Ext.data.Store', {
model: mod,
storeId:'recipStore'
});
store.add(recipient);
store.setData(recipient);
store.load();
var gridView = Ext.ComponentQuery.query('#gridViewId')[0];
gridView.setStore(store);
}
},
failure: function (result, request) {
console.log('api call was a failure');
},
scope: this
});
}
});
Now of course your data won't have "displayname, gender" etc.. but you should get the point.
I also found a working example here (I find it very sad that Sencha allows broken demos on their own website): http://demo.rasc.ch/eds/touch23/grid/grid/index.html
Hello i have the following problem:
After i generate the AP and install it on my phone the requisition store.load breaks in this specific store called CHAMADOS, but when i close the app and restart, it does not crash and bring me all the informations in the list...
It seems that the .load requires bring me the informations in the first time.
When i close and open it again the cache informations required before is add to the list, but the load required on the restart APP does not work.
It crashs and dont add the items to the LIST, but the store has data because on restart it appears, i have others store in this app and they work fine!
On brownser its fine, the problem is in the APK
Here is the view
{
height: '60%',
ui:'round',
style:'padding:18px 0; background:#FFF;',
xtype: 'dataview',
id: 'feedListagemChamados',
store: 'Chamados',
itemTpl: '<span>{nom_chamado}</span> '
}
Here is the store
Ext.define('WE3Chamados.store.Chamados', {
extend: 'Ext.data.Store',
config: {
model: 'WE3Chamados.model.Chamado',
autoLoad: true,
proxy: {
type: 'jsonp',
url: 'http://LINK?cod_usuario='+localStorage.getItem("usuarioId"),
callbackKey: 'callback',
reader: {
type: 'json',
rootProperty : 'chamados',
successProperty: 'success'
}
}
}});
Here is where i call the store to load (CONTROLLER)
showListaChamados: function (direcao) {
this.cleanApp();
store = Ext.getStore('Chamados').load();
store.load({
scope : this,
callback : function(records, operation, success) {
***IT BREAKS HERE ON RETURN***
Ext.Msg.alert('Opps', records[0].data.nom_usuario, this);
Ext.Viewport.animateActiveItem(this.getChamadoView(), this.getSlideTransition(direcao));
}
});
Ext.Msg.alert('Opps', store.data, this);
}
Here is the model
Ext.define('WE3Chamados.model.Chamado', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'cod_chamado'
},
{
name: 'nom_chamado'
},
{
name: 'des_chamado'
},
{
name: 'cod_equipe'
},
{
name: 'dat_cadastro'
},
{
name: 'dat_previsao'
},
{
name: 'dat_necessaria'
},
{
name: 'num_prioridade'
},
{
name: 'cod_projeto'
},
{
name: 'nom_usuario'
},
{
name: 'cod_status'
},
{
name: 'nom_projeto'
},
{
name: 'des_equipe'
},
{
name: 'nom_status'
},
{
name: 'nom_cliente'
},
{
name: 'cod_usuario'
},
{
name: 'cod_usuario_responsavel'
}
]
}});
I found the problem, it was in the localStorage.getItem("usuarioId") its not sendind it by the get, because it is after login, i think there is a bug in the js or its so fast that the comand to send the link cant get the localStorage.getItem.
Im trying using php SESSION now.