Position a image next a textfield in a form - extjs6

I have a form with some text fields. One of them is a image upload button.
I need to put the image preview box (a div) to the right side of the field (after the field button).
I already do the hard work by creating the div in the afterrender event:
listeners: {
afterrender: function ( cmp ) {
var container = this.body.dom.id;
$("#" + container ).append('<div style="position:absolute;
left:DONTKNOW;top:DONTKNOW" id="myPictureDiv"></div>');
}
}
how can I position elements in a ExtJS form? Can I use position:absolute ? But how to find the button position? What about form resizing?
EDIT: Image to illustrate scebotari's solution alignment problem:

One solution for this is to create the additional div as a component and to place it in a "fieldcontainer" with the main field.
{
xtype: 'fieldcontainer',
layout: 'hbox',
items: [{
xtype: 'textfield',
fieldLabel: 'Picture'
},{
xtype: 'component',
autoEl: 'div',
width: 32,
height: 32,
margin: '0 0 0 5',
style: 'border: 1px solid #d0d0d0; border-radius: 50%'
}]
}
Here is a fiddle illustrating this concept

This is the Form field
fieldLabel: 'My Field',
width: 330,
id: 'displayColumn',
name: 'displayColumn',
allowBlank : false,
value : '#CACACA',
This is the form listener:
listeners: {
afterrender: function ( cmp ) {
// Get the Window Container
var container = this.body.dom.id;
// Get the Component (ExtJS way)
var comp = Ext.getCmp("displayColumn");
// The ExtJS field ID is not the same you gave
var el = comp.getEl();
// Get the real Field ID
var displayColumnId = el.id;
// If you need its value...
var initialColor = comp.getValue();
// If you need to hide the field to make room to your div...
// I mean if you want to replace the field and keep the label...
// <YOUR_FIELD_ID>-triggerWrap
$("#displayColumn-triggerWrap").css("display","none");
// Append your div to the field container
// <YOUR_FIELD_ID>-bodyEl
$("#displayColumn-bodyEl").append(YOUR_DIV);
}
}
Do some style to the div as you wish

Related

Fit a wider table into PDF

This is in continuation to the question asked in github, Fit a wider table into PDF #261.
I'm reusing the same method(doc.autoTable) to create PDF out of different HTML inputs.
So, If I define the column style of 0th column as columnWidth: 'wrap', then the same style will be applied for all the HTML tables that invoke this particular method.
I'm not sure If I can follow long text example, as both the column names & table body are coming from HTML page directly. Whereas in the long text example, I'm seeing the column names being declared/defined as shown below
var columnsLong = getColumns().concat([
{title: "Title with\nlinebreak", dataKey: "text2"},
{title: "Long text column", dataKey: "text"},
]);
Now there are 2 questions.
1. I dont want to apply 'WRAP' for all the columns, as the table gets cut.
2. Need to apply 'wrap' for certain columns alone by mentioning the column name that comes from HTML/GSP page.
This is my code
var res = doc.autoTableHtmlToJson($(".printReportsCaveat")[0]);
doc.autoTable(res.columns, res.data, {
columnStyles : {'Plant':{columnWidth: 'wrap'},
'Mine':{columnWidth: 'wrap'},
0:{textColor: [0,105,170]}
},
margin: {top: 55, bottom : 110},
headerStyles: {
overflow: 'linebreak',
// columnWidth: 'auto',
halign: 'center'
},
styles : {
overflow: 'linebreak',
halign: 'center',
fontSize: 8
},
createdCell: function(cell, data) {
var group = $('#groupByValue').val();
addColorToCell(group, level3Flag, level2Flag, data, cell);
},
addPageContent : function(data) {
printHeadNFoot(doc, userDtl, data);
},
drawCell: function(cell, data) {
designCell(data,doc);   
},
});
Kindly help!
If I understand your issue correctly you can try referencing a specific column by index instead of by key. I.e. columnWidth: {0: columnWidth: 'wrap'}.

Extjs6 Filefield inside fieldset working fine with Chrome and not working in FF

(sencha fiddle for filefield inside fieldset)
I have a filefield inside a fieldset in extjs6. Fieldset is collapsed initially and I made filefield as button only. If I open the fieldset in chrome button shown and I don't see the button in firefox.
If I comment out line no 19 in the attached fiddle or make the fieldset open when starting, filefield looks good in both firefox and chrome.
Please refer the attached sencha fiddle and tell whats wrong.
Mohan, it sure does look like a bug.
I noticed that if you start out not collapsed then it works OK. So as a workaround you can chage your config to start out not collapsed and then collapse it in the afterrender:
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.form.Panel', {
title: 'Fieldsets with Files',
//labelWidth: 75,
frame: true,
bodyStyle: 'padding:5px 5px 0',
width: 550,
renderTo: Ext.getBody(),
//layout: 'column', // arrange fieldsets side by side
items: [{
xtype : 'fieldset',
name : 'docAttachment',
border: 2,
title : '<b>Attach your document</b>',
collapsible : true,
//collapsed : true,
//layout : {
// type : 'hbox',
// align : 'center',
// pack : 'center'
//},
items :[{
xtype: 'fileuploadfield',
name: 'fileuploads',
buttonOnly: true,
buttonText : 'Select a File...'
}],
listeners:{
'afterrender':function(){this.collapse();}
}
}]
});
}
});

TinyMCE render listbox items as html

I created a TinyMCE plugin and need the listbox items to display html. This is my plugin:
editor.addButton('icons', {
title: 'Foo',
text: 'Foo',
type: 'button',
onclick: function() {
editor.windowManager.open({
title: 'Foo',
width: 300,
height: 200,
body: [{
type: 'listbox',
label: 'Foo',
name: 'foo',
values: [{
title: '<em>Foo</em>', // <-- Mark save. Render as html.
value: 1
}],
}],
});
}
});
See also the fiddle: http://jsfiddle.net/allcaps/vqctac3d/
But the output looks like:
Expected:
How can I mark the list option title save so the contents is rendered as html?
Here is your updated snippet:
https://jsfiddle.net/mzvarik/1cwr07z6/55/
I was looking for same thing but listbox and it can be done like this:
(see fiddle for more)
editor.addButton('myshortcuts', {
type: 'listbox',
text: 'Vložit proměnnou',
values: self.shortcuts_data,
onselect: function() {
// do something
this.value(null); //reset selected value
},
onShow: function (event) {
var panel = $(event.control.getEl()),
button = event.control.parent().getEl();
var i=0;
panel.find('.mce-text').each(function(){
var item = $(this);
if (!item.next('.mce-menu-shortcut').length) {
// THIS WILL ADD HTML TO EXISTING MENU ITEM
item.after('<div class="mce-menu-shortcut">('+self.shortcuts_data[i].value+')</div>');
}
i++;
});
setTimeout(function(){
panel.css('width', 360);
panel.children().first().css('width', 360);
}, 5);
}
});
Here is screenshot:
Since noone else answered this question i will put the proposed solution/workaround from the comment into an answer.
Actually, it is not possible to insert html code using the tinymce way of listbox creation. But it is possible to style listboxes using css.
Due to the fact that listboxes and other tinymce UI elements get rendered dynamically it might be difficult to adress the correct html dom elements.
A workaround to this can be to exchange the listbox html after the listbox has been created. This is possible in case the ordering is known (and that is almost true).

How to use custom content to show the grid's tooltip?

How to use custom content to show the grid's tooltip? I want to show the tooltio ofcoloumn 2 and coloumn 3 ,and the content is a span which id called spanid or div which is called divid?
var tooltip = $("#Grid").kendoTooltip({
filter: "td",
width: 120,
position: "top",
content: value
}).data("kendoTooltip");
I try to write this,but it seems wrong.
var tooltip = $("#Grid").kendoTooltip({
filter: "td[3n]||td[2n]",
width: 120,
position: "top",
content: divid.html
}).data("kendoTooltip");
This is a working code for my scenario, it will work tool tip for all product names with class pLink
$(".pLink")
.kendoTooltip(
{
content: kendo.template($("#toolTipTemplate").html()),
position: "top",
width: "auto",
height: "auto",
animation: {
close: { effects: "fadeOut zoom:out", duration: 300 },
open: { effects: "fadeIn zoom:in", duration: 300 }
}
});
<script id="toolTipTemplate" type="text/x-kendo-template">
<p class="tooltipProductName">#=target.data('title')#</p>
</script>
//show the tooltip
tooltip = $("#grdData").kendoTooltip({
filter: 'td:not(:first-child, :nth-child(2), :empty)',
})
this will allow you to select first column , second column and it will also filter out empty cells. You can use the nth child selector. As this is a CSS3 selector, it will work from IE9+, chrome and firefox won't be an issue.
Hope this helps !

Reordering the subpanels of an ExtJS panel

I have an ExtJS Panel which contains a label in the first row and second row. Later i have added 4 sub panels each contains a checkbox, and 2 textfields( each sub panel in a row in the main panel). Then i have 2 Move up/Move down buttons which reorder these sub panels up/down by 1 row for each click of the up/down buttons. I am able to layout the main panel with all the subpanels but stuck at reordering the subpanels. How to handle this(reordering the subpanels) functionality in ExtJS?
The trick to change panel elements dynamically is to call doLayout function after change.
Not prettiest but working example of your problem:
var Panel1 = Ext.create('Ext.form.Panel', {
title: 'first',
items: [{
fieldLabel: 'text1',
xtype: 'textfield'
}, {
fieldLabel: 'text2',
xtype: 'textfield'
}, {
xtype: 'checkbox'
}]
})
var Panel2 = Ext.create('Ext.form.Panel', {
title: 'second',
items: [{
fieldLabel: 'text1',
xtype: 'textfield'},
{
fieldLabel: 'text2',
xtype: 'textfield'}]
})
var mainPanel = Ext.create('Ext.panel.Panel', {
title: 'main',
items: [Panel1, Panel2]
})
new Ext.Window({
width: 300,
height: 400,
layout: 'fit',
items: [mainPanel],
bbar: [{
text: 'reorder',
handler: function() {
var swap = mainPanel.items.items[0];
mainPanel.items.items[0] = mainPanel.items.items[1];
mainPanel.items.items[1] = swap;
mainPanel.doLayout();
}
}]
}).show();
This is for ExtJs 4.0.7, but trick works for earlier versions, just adjust panel creation syntax.

Resources