EXTJS Store issue with Null Values -- useNull: doesn't have an affect --Help? - combobox

Folks,
I have a combobox component backed by a JSONStore. The data loaded into the store is returning null for the combobox's value. The value is an int. The JSON decode process is converting the null value into a zero; causing the combobox to fail to render when it attempts to find the pk, zero that doesn't exist in its backing store.
I've found the useNull: config option for data.Field objects, upgraded to 3.3.0 Final and set my int value for the combobox to useNull:true. This isn't having any affect at all, unfortunately. The decoded value is still being changed from null to zero.
Any ideas about how to not set the field to a zero when the data for a JSON field is null?
Here's a pic of what's going on. Notice the data: value is zero, but the JSON value is null.
Thanks!
(gah! stoopid reputation < 10 so I can't directly post the pic. View it here: debug pic )
Also, here's my store's field config:
fields: [
{name:"id", type:"int"},
{name:"occurenceDate", dateFormat: 'Y-m-d\\TH:i:s', type:"date"},
{name:"docketNumber", type:"string"},
{name:"courtLocationId", type:"int", useNull:true},
{name:"assignedOfficerId", type:"int", useNull:true},
{name:"primaryIncidentTypeId", type:"int", useNull:true},
{name:"secondaryIncidentTypeId", type:"int", useNull:true},
{name:"tertiaryIncidentTypeId", type:"int", useNull:true},
{name:"incidentLocation", type:"string"},
{name:"summary", type:"string"},
{name:"personalItemsSeized", type:"string"},
"supplements",
"parties",
"judgeIds"
]

Try using it without type declaration. You may also use convert method:
{
name: "primaryIncidentTypeId",
convert: function(value, row) {
return (value == null) ? null : parseInt(value);
}
}

About the combo width: I usually use
defaults: {
anchor: '100%'
}
in the form declaration and have no problems with widths.
Isnt't it possible to provide convert functions from server side together with all other metadata?
And I'm still using ExtJS 3.2 - no need of any new bugs in the production systems :)

This also got me, you can additionally override the type convert function in Ext.data.Types to allow null values for integer type fields.
Ext.data.Types.INT.convert = function(v){
v = parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10);
return isNaN(v) ? null : v;
};

You must use defaultValue: null ,useNull : true because default value for integet type is zero
Example:
{name:"primaryIncidentTypeId", type:"int", useNull:true , defaultValue: null },

Related

Extjs store store cuts the last digits of a bigint values

I usesd Extjs 7.4. When I load data into an extjs store, I have the problem that the last digits are truncated for bigint values.
It doesn't matter if the model field type is int or number. Bigint values ​​are only displayed correctly if the type is string. I can't use the field as a string in the idProperty of the data model. Does somebody has any idea.
Maybe it is a limit of javascript, not ExtJs. In fact if you try to create a new object with a bigint property you get some truncated number:
var record = {
numericValue: 9223372036854776807,
stringValue: "9223372036854775807"
};
console.log(record);
It prints:
{
numericValue: 9223372036854776000,
stringValue: "9223372036854775807"
}
---EDIT---
A solution could be to pass for the convert config of the BigInt field defined in the store's model. Note that your property should be initially read by the store as a string. Doing like this, the property will correctly store BigInt values:
Ext.define("MyStore",{
extend: "Ext.data.Store",
fields: [
{
name: "bigIntProp",
convert: function (value) {
return BigInt(value);
}
}
]
});
var store = new MyStore();
store.add({ bigIntProp: '9223372036854775807' });
// This correctly print the big int value now
console.log(store.getAt(0).get("bigIntProp"));

how to set a value for one property for every record in an array

I have an array with 1 or more records. for every record for ex: there is a property id. I want to set this name to a default value : 8. Please help me.
Array: [{id: 2, name: "x"},{id: 4, name : "y"}]
I tried this way
if (!Ext.isEmpty(detailLineItems) && (detailLineItems.length > 0)) {
canProcess = false;
Ext.Array.forEach(array, function (r) {
if (r.id == 0 || Ext.isEmpty(r.id)) {
canProcess = true;
//how do I set this id
r.id == 6;
}
});
You should not change the internal id of records, as this may break everything; the value in record.id is expected by the framework to be the same value as record.get(record.idProperty). Instead, you should always use the setter method: record.set("id", 8).
But what you are essentially searching for is the defaultValue configuration on your model field:
fields:[{
name: 'id',
type: 'int',
defaultValue: 8
}]
Please be advised that the field id gets a special handling in ExtJS, as long as the model's idProperty defaults to id. A store can contain only one record with the same non-null value in the field defined by idProperty, so if you add them all to the same store you end up with only one of the records, and all other ones are deleted. So if you need multiple records with the same id in the store, you have to change the idProperty on the model to something else, e.g.
idProperty: 'someNonExistentProperty'
This then may cause issues with store sync operations. If you only try to set the id to a fixed value because your backend requires integer id, and the default id generated for new records by ExtJS is non-numeric (e.g. ext-myModel-1), you can check out identifier: 'negative'.
Your question is already answered by Alexander but just to mention, your code statement r.id == 6; is using the equality operator rather than the assignment operator r.id = 6; :-)

ExtJs: TextArea how to return value as an array instead of as a string?

On ExtJs 6.2, I have a form with a TextArea.
When user inputs text on several lines, for example :
line 1
line 2
The binded value is currently a string :
value= "line 1↵line 2"
But I need to send value (to server) as an array, when the store is submitting.
How to tell to the textarea to return input text as an array ?
value : ["line1", "line2"]
without to have to split string as array on the server-side.
Edit: I dont't want just to split value. Because I would to update the default behavior of the textarea to avoid to have to apply the split (in ViewController) each time that I using it.
I have created a fiddle with how I would approach it (assuming I have understood your requirements correctly!)
https://fiddle.sencha.com/#view/editor&fiddle/1uq7
This example turns an array into a string when coming into the textarea, and splits it on the way out.
Ext.define('ArrayTextArea', {
extend: 'Ext.form.field.TextArea',
alias: 'widget.arraytextarea',
setValue: function(val){
// if it's an array then join with a newline
if(Ext.isArray(val)){
val = val.join('\n');
}
return this.callParent([val]);
},
getValue: function(){
var val = this.callParent(arguments);
// split the value by newline char
return val.split('\n');
}
});
document.getElementById('textarea').value.split('↵')
You can use standard way provided by sencha http://docs.sencha.com/extjs/5.0.0/api/Ext.form.field.TextArea.html#placeholder-simple-getValue
Check this and reply.

Ext.data.field.Date - alternate format

I have to consume an API that provides to me the same field in records in the same array in two possible date formats:
Those where the second is zero will come in Y-m-d H:i format
Those where the second is non-zero will come in Y-m-d H:i:s format
E.g.
[{"date":"2016-12-16 09:52"},{"date":"2016-12-16 09:52:02"}]
An ExtJS store shall consume such API. The field definition:
fields:[{
name:'date',
type:'date',
dateFormat:'Y-m-d H:i:s'
altFormats:'Y-m-d H:i' // <- how can I define this in an `Ext.data.field.Date`?
}]
I know there is a convert function, in which I can write some mess like this:
convert:function(value)
if(Ext.isDate(value)) return value;
var valueWithSecond = Ext.Date.parse(value,"Y-m-d H:i:s");
if(Ext.isDate(valueWithSecond)) return valueWithSecond;
var valueWithoutSecond = Ext.Date.parse(value,"Y-m-d H:i");
if(Ext.isDate(valueWithoutSecond)) return valueWithoutSecond;
}
As can be seen easily, the field definition would be far more readable. Is such a field definition available?
You can extend Ext.data.field.Date and override convert so you'll be able to use it like:
{
name:'date',
type:'my-date',
dateFormat:'Y-m-d H:i:s'
altFormats:'Y-m-d H:i'
}

CakePHP saveField NULL value in a INT column

I want to update one column which is an INT with a NULL value. I'm using CakePHP 2.3 with the saveField('field', 'value') method.
Here is my code :
$this->Customer->id = $customer_id;
if ($this->Customer->saveField('account_id', 'NULL')) {
//Do some stuff
}
So when I put 'NULL', the row is updated to 0. I tried NULL without quotes and the row is not updated.
EDIT :
The field in the db accepts NULL value.
Do you have any idea ?
Thanks
Do not pass 'NULL' as a string but as null value:
if($this->Customer->saveField('account_id', null))
{
//do some stuff
}
else
{
//do you get anything here ?
debug($this->Customer->validationErrors);
}
I've had a similiar problem caused by a Upload Behaviour that had validations preventing the saving. Check your models, it might help. I assume saveField returns true even when validation rules prevent saving.

Resources