In my toolbar there is checkbox used for enabling and disabling tooltip. If the checkbox is checked then I should enable tooltip and it is working if not then I should disable it also working. After disabling tooltip, when click on toolbar not on any item in the toolbar then also it is enabling.
toogleTooltip is a handler of checkbox
function toggleTooltip() {
debugger;
if (Ext.getCmp("msai_tool_tip").checked) {
Ext.QuickTips.enable();
while (!Ext.QuickTips.isEnabled())
Ext.QuickTips.enable();
} else {
Ext.QuickTips.disable();
while (Ext.QuickTips.isEnabled())
Ext.QuickTips.disable();
}
}
This is my toolbar creation code:
Ext.QuickTips.init();
var tb = new Ext.Toolbar({
id: 'form_menu_bar',
renderTo: Ext.get('newproducttitle').dom,
items: [{
tooltip: {
text: "Click on this button to generate the template and save it in server.",
title: "Save",
xtype: "quicktip"
},
iconCls: 'msai_save_template',
handler: generateTemplate
}, {
tooltip: {
text: "Click on this button to generate the template.",
title: "Save to clipboard",
xtype: "quicktip"
},
iconCls: 'msai_save_clipboard',
handler: generateTemplateClipboard
}]
});
Please suggest some solution so that I should not show tooltip, if user click on toolbar not in any item.
Please find the below fiddle to check working example:
https://fiddle.sencha.com/#view/editor&fiddle/2c7k
Code snippet:
Ext.QuickTips.init();
var tb = new Ext.Toolbar({
renderTo: document.body,
width: 600,
height: 100,
items: [{
// xtype: 'button', // default for Toolbars, same as 'tbbutton'
text: 'Button',
tooltip: 'button'
}, {
xtype: 'splitbutton', // same as 'tbsplitbutton'
text: 'Split Button',
tooltip: 'Split Button'
}, {
xtype: 'checkbox',
boxLabel: 'enable tooltip',
checked: true,
listeners: {
check: function (checkbox, newValue, oldValue) {
if (newValue) {
Ext.QuickTips.enable();
} else {
Ext.QuickTips.disable();
}
}
}
}]
});
Related
I have my ExtJS 4.2.1 MVC Application.
Inside my app, I have a grid with a toolbar. The toolbar has 2 buttons, "Add New" and "Edit Record".
Inside my Controller.js I listen for my toolbar buttons click events.
this.control({
'toolbar #newRecord': {
click: this.addRecord
},
'toolbar #editRecord': {
click: this.editRecord
},
'[xtype=editshiftcode] button[action=commit]': {
click: this.saveRecord // here I have to add or edit
}
}
Then I have Window that I want to use for editing and adding records:
Ext.define('App.view.EditShiftCode', {
extend: 'Ext.window.Window',
alias: 'widget.editshiftcode',
height: 250,
width: 550,
title: 'Add / Edit Shift',
modal: true,
resizable: false,
layout: 'fit',
glyph: Glyphs.PENCIL,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [{
xtype: 'container',
//height: 175,
layout: {
type: 'hbox',
align: 'strech'
},
items: [{
xtype: 'form',
bodyPadding: 10,
autoScroll: false,
itemId: 'editForm',
defaults: { // defaults are applied to items, not the container
allowBlank: false,
allowOnlyWhitespace: false,
msgTarget: 'side',
xtype: 'textfield'
},
items: [
{
xtype: 'textfield',
name: 'ShiftCode',
fieldLabel: 'Code'
},
{
xtype: 'textfield',
name: 'Description',
fieldLabel: 'Description'
},
{
xtype: 'hiddenfield',
name: 'ShiftType'
},
{
xtype: 'hiddenfield',
name: 'ShiftTypeId'
},
{
xtype: 'textfield',
name: 'Hours',
fieldLabel: 'Hours per Day'
},
{
xtype: 'colorcombo',
name: 'ColorHex',
fieldLabel: 'Color'
},
{
xtype: 'checkbox',
fieldLabel: 'Active',
name: 'IsActive',
}
],
}]
}],
buttons: [
{
text: 'OK',
action: 'commit',
glyph: Glyphs.SAVE
},
{
text: 'Cancel',
action: 'reject',
glyph: Glyphs.CANCEL
}]
});
me.callParent(arguments);
},
});
My editRecord function is:
editRecord: function (button, e, options) {
var me = this;
var window = Ext.create('App.view.EditShiftCode');
window.show();
},
My addRecord function is:
addRecord: function (button, e, options) {
var me = this;
var window = Ext.create('App.view.EditShiftCode');
window.show();
},
My saveRecord function is:
saveRecord: function (button, e, options) {
// here i need to know what operation im going to perform.
// if Im going to edit then I have to update my form record to my store record
// if im going to add then I need to add a new item to my store.
}
Is this correct? To use the same function to perform 2 different actions? And if so, how can I know what action am I going to perform and how to do it?
Thanks
This way always worked for me:
User selects a record in the grid
User clicks "Edit record"
I use loadRecord to load the selected record in the form
When he clicks OK I call updateRecord
If user clicks "Add record" I create a new blank record and go to step 3
If he clicks OK after adding record, I just add the new record to the grid - you can easily know if the record is new or existing by checking phantom flag. So if record.phantom === true then it is new.
Ext.define('CCCC.view.Header', {
extend: 'Ext.toolbar.Toolbar',
requires: ['CCCC.view.header.MasterLogo',
'Ext.button.Button'],
alias: 'widget.mainheader',
itemId : 'header',
width: '100%',
height: 100,
renderTo: document.body,
initComponent: function() {
var me = this;
me.items = [
{
xtype: 'tbfill'
},
{
xtype: 'tbseparator'
},
{
xtype: 'button',
text: 'Logout',
itemId: 'logout',
listeners: {
handler: function() {
var me = button.up('WidgetName');
me.fireEvent('logoutClicked', button, e);
Ext.log('logout clicked');
}
}
},
i have added the logout button to the toolbar as xtype. it is showing as lable , not able to click the "logout" button. Please let me know why "logout" button is not clickable ?
The handler should be in the button config, not in the button's listener config:
{
xtype: 'button',
text: 'Logout',
itemId: 'logout',
handler: function() {
var me = button.up('WidgetName');
me.fireEvent('logoutClicked', button, e);
Ext.log('logout clicked');
}
}
Alternatively, if you want to use a listener, you should listen to the click event instead:
{
xtype: 'button',
text: 'Logout',
itemId: 'logout',
listeners: {
click: function() {
var me = button.up('WidgetName');
me.fireEvent('logoutClicked', button, e);
Ext.log('logout clicked');
}
}
}
I have a panel which is not a form, yet it's used like a form. I need to disable the "addButton" button when a text field is invalid. The disabling in the text Field's validator function works, but visually the button still looks enabled.
How can I tell a button to be visually disabled via the validator method on my text field?
Here is the code:
items: [
{
xtype: 'textfield',
validator: function(value) {
var reg = /^\d+(,\d+)*$/;
var addButton = this.ownerCt.down('[itemId=addButton]');
if (reg.test(value)===false) {
addButton.disabled=true;
addButton.allowDepress=false;
return "Enter whole numbers separated by comma";
}
addButton.disabled=false;
addButton.allowDepress=false;
return true;
},
Here is working sample http://jsfiddle.net/H76fQ/2/
var button = Ext.create('Ext.button.Button',{
renderTo: Ext.getBody(),
text: 'Ok',
disabled: true
});
Ext.create('Ext.form.field.Text',{
allowBlank: false,
renderTo: Ext.getBody(),
listeners:{
afterrender: function(){
this.validate();
},
validitychange: function(me, isValid){
button.setDisabled(!isValid);
}
}
});
To disable the FormPanel’s submit button,You can set the FormPanel’s monitorValid to true and the submit button’s formBind to true.
items: [{
xtype: 'ux.form',
monitorValid: true, // Must be added
layout: {
type: 'hbox',
align: 'start',
pack: 'stretch'
},
items: [{
name:"testing",
xtype:'textfield',
fieldLabel:'Test',
allowBlank:false, // This is the property which will check the validation
},
{
xtype: 'ux.button',
text: 'Submit',
width: 120,
formBind: true
}]
}]
I want to add some buttons in 'window' header, instead of 'X'.
Draggable property must be saved!
It should look like this:
You can specify the tools(Ext.Panel.Tool) config for the window!
tools:[{
type:'refresh',
tooltip: 'Refresh form Data',
handler: function(event, toolEl, panel){
// refresh logic
}
},
{
type:'help',
tooltip: 'Get Help',
handler: function(event, toolEl, panel){
// show help here
}
}]
There are 25 predefined buttons but you can customize your own.
It's also possible to define xtype: 'header' element and customize header of window/panel more precisely:
header: {
xtype: 'header',
titlePosition: 0,
defaults: {
margin: '0 10px'
},
items: [
{
xtype: 'textfield',
value: "Test Search",
tooltip: "Search something",
width: 300
},
{
xtype: 'container',
flex: 1
},
{
xtype: 'button',
text: "Test Button",
tooltip: "Add something",
iconCls: 'add',
handler: Ext.bind(function() {
console.log('does something');
}, this)
}
]
}
The only limitation I could see for now is inability to use '->' elements as items, but it's still possible to use their full class names (ie Ext.toolbar.Fill) or config by xtype: 'tbfill'.
when i disable the button it's tooltip also disables. Is there a way to show the tooltip even the button is disabled.
//create my button
var myButton = Ext.create('Ext.Button', {
tooltip : 'my Button Tooltip Text',
id : 'my-button ',
iconCls : 'star-icon',
handler: Ext.Function.pass(_rmp.mediaManager.myButtonFunction, this)
});
//disable my button
Ext.getCmp('my-button').disable();
EDIT:
It is not working as expected on firefox(I am using version 8.0.1) for other browsers(chrome,safari, opera) tooltip works as expected.
#jeewiya
By default, ExtJS framework shows the tooltip on the disabled button. Here is what I had on my Reset button:
{
text: 'Reset',
tooltip : 'my Button Tooltip Text',
id : 'my-button ',
handler: function() {
this.up('form').getForm().reset();
}
}
And, the following image shows that the tip appears even after the Reset button was disabled
In case, you want to try out my sample, here is the complete code that I have tested with ExtJS 4.0.7 and is working as expected:
Ext.onReady(function(){
Ext.tip.QuickTipManager.init();
var form = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
title: 'Simple Form',
bodyPadding: 5,
width: 350,
layout: 'anchor',
defaults: {
anchor: '100%'
},
// The fields
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank: false
},{
fieldLabel: 'Last Name',
name: 'last',
allowBlank: false
}],
// Reset and Submit buttons
buttons: [{
text: 'Reset',
tooltip : 'my Button Tooltip Text',
id : 'my-button ',
handler: function() {
this.up('form').getForm().reset();
}
}, {
text: 'Submit',
formBind: true,
disabled: true,
handler: function() {
Ext.getCmp('my-button ').disable();
}
}],
renderTo: Ext.getBody()
});
});