I have a problem with my date sorter. I get my date out a XML file and looks like this:
<date>18-10-2011</date>
my store is this:
Ext.define('blockedList', {
extend: 'Ext.data.Model',
fields: [{
name: 'sourceFile',
type: 'text',
mapping: 'sourceFile'
}, {
name: 'summaryFile',
type: 'text',
mapping: 'summaryFile'
}, {
name: 'date',
type: 'date',
mapping: 'date'
}, {
name: 'total',
type: 'float',
mapping: 'total'
}]
});
But when i sort on date it is not doing the correct sorting. If i have these dates: 1-1-2011, 3-1-2011 and 1-2-2011 it sorts like this:
1-1-2011
1-2-2011
3-1-2011
how can i get this sorting working like it should?
Thanks
I believe you need to set the dateFormat within the field. For example I have dates returning from a JSON request and the field has dateFormat: 'MS' attribute.
I'd give this a read on Ext's dateformats. Hope that helps.
Related
Can I have multiple inputs for any given type?
I am trying to customize the query builder by adding two date range pickers (from date and to date) to each rule.
filters: [
{
id: 'category',
label: 'Category',
type: 'integer',
input: 'select',
values: {
1: 'Books',
2: 'Movies',
3: 'Music',
4: 'Tools'
},
{
id: 'date',
label: 'Date Range Picker',
type: 'date',
validation: {
format: 'YYYY/MM/DD'
},
plugin: 'datepicker',
plugin_config: {
format: 'yyyy/mm/dd',
todayBtn: 'linked',
todayHighlight: true,
autoclose: true
}
}
after select Category I want to display from Date & to Date input picker
I have a model:
Ext.define('CrudTest.model.User', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'Name', type: 'string' },
{ name: 'PhoneNumber', type: 'int' },
{ name: 'Address', type: 'string' },
{ name: 'StateId', type: 'int', reference: 'State' },
],
validators: [
{ type: 'presence', field: 'Name', message: 'define name, please' },
{ type: 'length', field: 'PhoneNumber', max: 8, messsage: 'lower than 8 digit' },
],
proxy: {
type: 'ajax',
api: {
create: 'home/new',
read: 'home/users',
update: 'home/Edit',
destroy: 'home/Delete'
},
},
});
and a form that load data to form by loadRecord() and my handler code for submit button is:
var form = this.up('form').getForm();
if (form.isValid()) {
form.getRecord().save();
}
it make a post request through my proxy model good. but the body of request just have dirty(edited) fields. why i don't have other fields?
but in request body i have just dirty fields. why? i know updateRecord() uses getFieldValues([onlyDirty=false]), how can send all fields values?
I use extjs 5
Finally find the problem. Ext.data.writer.Writer has a config property writeAllFields
So i change the proxy to this:
proxy: {
writer:{ writeAllFields:true },
type: 'ajax', //also works with type: 'direct',
api: {
create: 'home/new',
read: 'home/users',
update: 'home/Edit',
destroy: 'home/Delete'
},
You can set crtical: true on the Model to any fields you always want written whether changed or not, e.g.
{ name: 'title', type: 'string', critical: true }
I am very new to sencha touch, and i am using Architect. I have a controller "RegisterUser"(controlleractiontap) which has a function.. when i fill in some user data and I click register button in my formview it will write the user to my local database.
I have a model called "userModel" which contains the following:
fields: [
{
name: 'Username',
type: 'string'
},
{
name: 'Password',
type: 'string'
},
{
name: 'Firstname',
type: 'string'
},
{
name: 'Lastname',
type: 'string'
},
{
name: 'Phonenumber',
type: 'string'
},
{
name: 'Email',
type: 'string'
}
],
validations: [
{
type: 'presence',
field: 'Username'
},
{
type: 'email',
field: 'Email'
},
{
type: 'length',
field: 'PhoneNumber',
max: 10,
min: 10
}
the problem: how do i call my validators in the controller so it will validate the fields in my form?
if i missing some information to make it more clear just let me now.
Thanks in advance!
var val=Ext.create('talkbag.model.Registration',new Ext.getCmp("registration").getValues());
where "registration" is the id assigned to the view that extends Ext.form.Panel
var check=val.validate();
now you can check like this if (!check.isValid())
I´ve designed an application based on the MVC Pattern. So I also defined my proxies, fields and validators in my model. Here for example is a model for a list of countries:
Model
Ext.define('LT.model.Country',{
extend: 'Ext.data.Model',
fields: [{name: 'id',type: 'int'},
{name: 'name', type: 'string'},
],
validations: [
{type: 'length', field: 'name', min: 2}
],
proxy: {
type: 'rest',
url: '/country',
reader: {
type: 'json'
},
writer: {
type: 'json'
}
}
});
And here is the store for using this model:
Store:
Ext.define('LT.store.Country', {
extend: 'LT.base.store.Base',
model: 'LT.model.Country'
});
The store is shown in a Grid Panel, where i use the RowEditor Plugin to enable adding and editing rows directly in grid view
Grid Panel:
Ext.define('LT.view.country.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.country-list',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
clicksToMoveEditor: 1
})
],
store : 'Country',
columns: [
{header: 'ID', dataIndex: 'id', width: 50},
{header: 'Name', dataIndex: 'name', flex: 3, editor: 'textfield'},
],
tbar: [{
xtype: 'button',
action: 'add',
text: 'Add'
},{
xtype: 'button',
action: 'delete',
text: 'Delete'
}]
});
My problem now is, that the Validation Errors are not show if you edit data in grid view. If the data doesn´t match the validation criterias, then it´s not submitted to the proxy (which is fine), but the user also doesn´t get an error message, that the inserted data is invalid.
I found some (not really beautiful) workarounds - but maybe anyone knows another solution to add validation functionality to rowediting in extjs?
Thanks in advance & cheers,
Michael
Integrating Ext.grid.panel validation and Ext.data.Model.validations
The above response talks about the approach that you can follow
What's the best way to go about adding validation to a date field in a model
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'phone', type: 'string'},
{name: 'gender', type: 'string'},
{name: 'username', type: 'string'},
{name: 'alive', type: 'boolean', defaultValue: true}
],
validations: [
{type: 'presence', field: 'age'},
{type: 'length', field: 'name', min: 2},
{type: 'inclusion', field: 'gender', list: ['Male', 'Female']},
{type: 'exclusion', field: 'username', list: ['Admin', 'Operator']},
{type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/}
]
});
Let's say the above code contained a 'dob' field for date of birth. How would I go about adding a validation for it?
My assumption is that I would use :
{type: 'format', field: 'dob', matcher: /([a-z]+)[0-9]{2,3}/}
but would use a regex that's designed to validate a date. Is there a better way to do this? I noticed that date fields on forms use their own validation methods to highlight a date field. Is there something like that for date fields in models?
add validate method to Ext.data.validations (singleton),
and it will be use at Ext.data.Model.validate().
take a look at src