Extjs 4: how to make a text field input to an editable div? - extjs4

I have a text field (or time/date field) with mask. __:__:__ I have to change the color of "_" from black to white. Has Extjs 4 any solution to change input to (editable) div?

Have you tried overriding the base fieldSubTpl property for your field? I.e, adding the property with a as a div element instead of input:
fieldSubTpl: [ // note: {id} here is really {inputId}, but {cmpId} is available
'<div id="{id}" type="{type}" {inputAttrTpl}',
' size="1"', // allows inputs to fully respect CSS widths across all browsers
'<tpl if="name"> name="{name}"</tpl>',
'<tpl if="value"> value="{[Ext.util.Format.htmlEncode(values.value)]}"</tpl>',
'<tpl if="placeholder"> placeholder="{placeholder}"</tpl>',
'{%if (values.maxLength !== undefined){%} maxlength="{maxLength}"{%}%}',
'<tpl if="readOnly"> readonly="readonly"</tpl>',
'<tpl if="disabled"> disabled="disabled"</tpl>',
'<tpl if="tabIdx"> tabIndex="{tabIdx}"</tpl>',
'<tpl if="fieldStyle"> style="{fieldStyle}"</tpl>',
' class="{fieldCls} {typeCls} {editableCls}" autocomplete="off"/>',
{
disableFormats: true
}
],

Now I am here, using this tpl:
fieldSubTpl: [
'<div stlye="position: inherit; top: 0px; left: 0px" id="{id}-div" contentEditable='+!this.disableSel+' type="{type}" {inputAttrTpl}',
' size="1"',
'<tpl if="value"> value="{[Ext.util.Format.htmlEncode(values.value)]}"</tpl>',
'<tpl if="placeholder"> placeholder="{placeholder}"</tpl>',
'<tpl if="tabIdx"> tabIndex="{tabIdx}"</tpl>',
'<tpl if="fieldStyle"> style="{fieldStyle}"</tpl>',
' class="{fieldCls} {typeCls} {editableCls}" autocomplete="off">{[Ext.util.Format.htmlEncode(values.value)]}</div>' +
'<input type="text" id="{id}" value="{[Ext.util.Format.htmlEncode(values.value)]}" ' +
'style="visibility: hidden; height: 0px; width: 0px; " />',
{
disableFormats: true
}
]
And I made a new plugin extended the original, change all this.inputTextElement.value to get or set HTML
this.getPicker().on('select', function (p, r, o){
Ext.get(this.id + '-inputEl-div').setHTML(r.data.disp);
}, this);
And on some other event the hidden input and div change their values, but it's not the ultimate version of my sollution. Now I have lots of work yet... Huh... :)
And if you know other idea, please post it!

An other solution I'm trying:
buildDivsByFormat: function () {
// 12: 'h:i A', '03:15 PM'. 'h:i:s.u A' 24: 'H:i' 'H:i:s.u' instead.
var w = 8;
var divs = {};
if(this.format.indexOf("i") > -1)
divs.i = '<div style="padding:0px 0px 1px 0px;width:'+w*2+'px;min-width:'+w*2+'px;max-width:'+w*2+'px;float:left;display:inline-block;"' +
contentEditable="'+!this.disableSel+'" id="'+this.id+'-div-i'+'"> </div>';
... // making this with other format elements
var d = '';
var formatArray = this.format.split('');
for(var i = 0; i < formatArray.length; i = i + 1){
var currentChar = formatArray[i];
if(formatArray[i] === ":") currentChar = 'dp';
if(formatArray[i] === ".") currentChar = 'p';
if(formatArray[i] === " ") currentChar = 'sp';
d = d + divs[currentChar];
}
this.divs = d;
return d;
}
Making divs by format and inserting them to this tpl's div:
fieldSubTpl: [
'<div stlye="position: inherit; top: 0px; left: 0px" id="{id}-div" type="{type}" {inputAttrTpl}',
' size="1"',
'<tpl if="value"> value="{[Ext.util.Format.htmlEncode(values.value)]}"</tpl>',
'<tpl if="placeholder"> placeholder="{placeholder}"</tpl>',
'<tpl if="tabIdx"> tabIndex="{tabIdx}"</tpl>',
'<tpl if="fieldStyle"> style="{fieldStyle}"</tpl>',
' class="{fieldCls} {typeCls} {editableCls}" autocomplete="off">' +
'</div>' +
'<input type="text" id="{id}" value="{[Ext.util.Format.htmlEncode(values.value)]}" ' +
'style="visibility: hidden; height: 10px; width: 0px; " />',
{
disableFormats: true
}
]
Then I do some changing function... I have some problems: I can't coloring this version, but... bigger problem is: if input is visibility: hidden;, it makes space after my tpl's div... on display: none makes time picker to absolute 0 0 position of window, not to the field (div)... Has anybody an idea about this?

Related

Barcode CODE_128 using PrintHTML with Qz Tray

Good Day All,
Right now, i'm trying to print using HTML with Qz-Tray. Can i make a barcode on that template HTML. The Problem is, that HTML template is STRING so it can not be change it using Javascript and I'm Trying to use Libre Font 128 Font Family but still not working.
https://www.w3schools.com/howto/tryit.asp?font=Libre%20Barcode%20128 i want to use that library, in this
function printHTML() {
var config = getUpdatedConfig();
var colA = '<h2>* QZ Print Plugin HTML Printing *</h2>' +
'<span style="color: #F00;">Version:</span> ' + qzVersion + '<br/>' +
'<span style="color: #F00;">Visit:</span> https://qz.io/';
var colB = '<img src="' + getPath() + '/assets/img/image_sample.png">';
var printData = [
{
type: 'html',
format: 'plain',
data: '<html>' +
' <table style="font-family: monospace; border: 1px;">' +
' <tr style="height: 6cm;">' +
' <td valign="top">' + colA + '</td>' +
' <td valign="top">' + colB + '</td>' +
' </tr>' +
' </table>' +
'</html>'
}
];
qz.print(config, printData).catch(displayError);
}
or this https://barcode-coder.com/en/barcode-jquery-plugin-201.html

vue.js ternary style binding - invalid expression: Unexpected token ']'

partNav = Vue.component('part-nav', {
data:
navItems: [
{
subItems: [
{...}
{...}
]
}
{...} # another object in navItems array
]
template: '
<div
v-for="(navItem, navItem_index) in navItems"
:style="[ navItem.subItems ? { height: (1.3 + 2 * 0.75) * navItem.subItems.length + \'rem;\' } ]"
>
</div>
'
})
invalid expression: Unexpected token ']' in ...
How can I apply this style binding - if navItem in v-for has subItems array then apply style (height of one element multiplied by subItems length)?
As help I've been used this post.
I think you just want this:
:style="navItem.subItems ? { height: (1.3 + 2 * 0.75) * navItem.subItems.length + 'rem' } : {}"
A ternary needs all 3 arguments (hence the name). There's also no need for the square brackets.
I've retained your original condition of navItem.subItems. That'll only work if the subItems array can be missing (i.e. null or undefined). An empty array doesn't count as falsey so if that's the case you're interested in you'll need to adjust it accordingly.
You could drop the ternary and just use a check
:style="navItem.subItems && { height: (1.3 + 2 * 0.75) * navItem.subItems.length + \'rem;\' }"
If you want to check if the array is not empty then you can do this
:style="navItem.subItems && navItems.subItems.length && { height: (1.3 + 2 * 0.75) * navItem.subItems.length + \'rem;\' }"

Knockout Table View of Array list without Names

I'm new to knockout and JS programming. I have a JSON result set returned, that would be two nested arrays, like this wherein each array could be variable in size:
listToReturn
[0] Count:4 -------> [0] "CHANNEL", [1] "HOUR", [2] "DATE", [3] "TRANSACTION_CNT"
[1] Count:122 ----->
[0] 101, [1] 11, [2] 03/01/2014, [3] 400,
[4] 101, [5] 6, [7] 03/12/2014, [8] 232
(these are the individual values for the rows above that repeat)
I want to build table that displays these nicely. Essentially, that will handle any result set that comes back with variable number of columns and data that will be populated in the table, like this:
CHANNEL HOUR DATE TRANSACTION_CNT
101 12 03/01/2014 400
101 6 03/12/2014 232
I have the first part working for the column headers:
Within ViewModel:
$.ajax({
type: 'get',
url: 'Reports/GetReportData',
data: { requestObj: req },
contenttype: 'application/json',
datatype: 'json',
success: function(result) {
if (result) {
document.getElementById("reportOutputfieldSet").style.display = "block";
ko.utils.arrayForEach(result[0], function (data) {
self.cnames.push(data.replace(",", " "));
});
ko.utils.arrayForEach(result[1], function (data) {
self.cdata.push(data.replace(",", " "));
});
In the View:
<tr data-bind="foreach: cnames" style="color: white; background-color: #003399; font-weight: bold; width: 600px">
<td data-bind="text: $data" style="width: 25%"></td>
</tr>
After several different attempts to properly construct a display for the data, I'm coming up empty handed. I first tried going through and getting the unique values for each one and displaying them in the UI, but that didn't work. :(
var noColumns = result[0].length;
var thisArray = function () {
if (result[1].length === 0)
return [];
for (var column = 0; column < result[0].length - 1; column++) {
for (var row = column; row < result[1].length - 1; row++) {
if (row % noColumns == 0) {
switch (column) {
case 0:
self.columnOne.push(result[1][row]);
break;
case 1:
self.columnTwo.push(result[1][row]);
break;
}
}
}
}
return self.columnOne();
};
In the View:
<tbody>
<!-- ko foreach: columnOne -->
<tr style="border-bottom: solid 1px #003399;">
<td data-bind="text: $data" style="width: 25%"></td>
<!-- ko foreach: columnTwo -->
<td data-bind="text: $data" style="width: 25%"></td>
<!-- /ko -->
</tr>
<!-- /ko -->
</tbody>
I have a feeling I need a custom ko.binding, but really at a loss as to how to get started with it. Anyone's help is greatly appreciated. Thanks in advance!

Extjs 4.1.1 How to debug Xtemplete

I am using Ext 4.1.1 version.
I want to know How to debug the Xtemplate. i.e.
e.g.
'<tpl for="outerObject">',
'<tpl for="innerObject">',
'<span class="abc">{myValue}</span>',
'</tpl>',
'</tpl>',
Now I want to know what Value outerObject has, depending upon that want to loop into innerObject, and so on.
Please tell me any way to degug Xtemplate.
The easiest way is to get into the browser's debugger:
tpl: [
'<tpl for="outerObject">',
'{% debugger; %}'
'<tpl for="innerObject">',
'<span class="abc">{myValue}</span>',
'</tpl>',
'</tpl>'
]
You can execute arbitrary inline code in XTemplate. Hence, you can call console.log in order to print some object variable:
'{[console.log(values.outerObject)]}',
I know this is "old" but, if you have your own template or have anyway to come to the template, you can actually add the debugger; command and chrome will jump into the debugger.
extraRowTpl: [
'{%',
'values.view.rowBodyFeature.setupRowData(values.record, values.recordIndex, values);',
'debugger;', **<!-- WILL STOP HERE**
'this.nextTpl.applyOut(values, out, parent);',
'%}',
'<tr class="' + Ext.baseCSSPrefix + 'grid-rowbody-tr {rowBodyCls}">',
'<td class="' + Ext.baseCSSPrefix + 'grid-cell-rowbody' + ' ' + Ext.baseCSSPrefix + 'grid-cell ' + Ext.baseCSSPrefix + 'grid-td" colspan="{rowBodyColspan}">',
'<div class="' + Ext.baseCSSPrefix + 'grid-rowbody' + ' {rowBodyDivCls}">{rowBody}</div>',
'</td>',
'</tr>']
Hope I could help!
Greetz

Sencha Touch - How to change the style of a list item based on its previous value

I have a list (xtype: 'list') and I use an XTemplate to customize it. It looks like this:
itemTpl: new Ext.XTemplate('<div>',
'<span style="display: inline-block; width: 100px">{itemName}</span>',
'<span style="display: inline-block; width: 100px">{price}</span>','</div>')
I would like to change the color of {price} (using css I guess) based on the previous and current value:
If [current value] > [previous value] color it green.
If [previous value] > [current value] color it red.
The price value is updated like this:
var itemList = Ext.getCmp('itemList');
var store = itemList.getStore();
store.getAt(i).set('price', currentPrice);
While i is the number of item (or row in the list) that is updated and currentPrice is the new value. This code is executed by a function that is called once every second.
I know there is an option to have conditions inside an XTemplate, but all the examples I saw compare the new value with a constant. How can I change the color of {price} by comparing the new value to the old one?
You may add 'color' property to store when the store has loaded/created or while it is filling/creating.
store.each(function(item, i) {
var previousItem = store.getAt(i-1);
if (previousItem) {
var previousPrice = previousItem.get('price');
var price = item.get('price');
item.set('color', (price > previousPrice) ? 'green' : 'red');
}
})
Then you can use property in template
itemTpl: new Ext.XTemplate('<div>', '<span style="display: inline-block; width: 100px; color: {color}">{itemName}</span>', '<span style="display: inline-block; width: 100px">{price}</span>','</div>')