Changing the name of a button in jquery-steps - jquery-steps

I have included the jquery-steps plugin.
How can I change the buttons texts?
Now it says "finish" I want to change that into "go"
Thanks

Check out the following link. You can change all labels on initialization.
var settings = {
labels: {
current: "current step:",
pagination: "Pagination",
finish: "Finish",
next: "Next",
previous: "Previous",
loading: "Loading ..."
}
};
$("#wizard").steps(settings);`

I just needed to change button text depending on condition. And it can be done without changing settings just like that
if(true){
$('a[href$="finish"]').text('Go');
}else{
$('a[href$="finish"]').text('No Go');
}

You can do this:
form.steps({
headerTag: "h4",
bodyTag: "section",
transitionEffect: "fade",
labels:
{
finish: "Go",
},
onStepChanging: function (event, currentIndex, newIndex)
{
//change color of the Go button
$('.actions > ul > li:last-child a').css('background-color', '#f89406');
form.validate().settings.ignore = ":disabled";
return form.valid();
},
onFinishing: function (event, currentIndex)
{
form.validate().settings.ignore = ":disabled";
return form.valid();
},
onFinished: function (event, currentIndex)
{
form.submit();
}
});

If the label / text of the buttons should change dynamically depending on the language, you can use this:
/* dynamic change prev-next button text language (check lang attribute in html tag) */
var language = $('html').attr('lang');
$(window).on('load', function () {
if(language != 'de'){
$('a[href$="next"]').text('Next');
} else {
$('a[href$="next"]').text('Weiter');
}
});

Related

Extjs: in TabPanel, how to put a checkbox in each tab's header?

it seems very straight forward, but after a lot of tries and online searching, still no luck with it.
environment:
ExtJS 3.4
here is a jsfiddle I am working on: http://jsfiddle.net/v4ZzT/8/
new Ext.TabPanel({
renderTo: 'tab-with-chkbox',
activeTab: 0,
items:[
{
title: '<input type="checkbox"> Disabled?</input>',
html: 'Sample panel'
}
]
});
but that checkbox doesn't respond to click.
also found this link on sencha forum:
http://www.sencha.com/forum/showthread.php?114794-Checkbox-in-tab-header
it recommends changing iconCls. but I couldn't find a way to detect if this icon is clicked or not.
The input box gets checked, however the tab panel event handler redraws the title after handling the click event. You will need to modify the click event handler for the TabPanel in order to change the title being drawn, although a little messy you can do something like this:
findTargets: function (e) {
var item = null,
itemEl = e.getTarget('li:not(.x-tab-edge)', this.strip),
input = e.getTarget('input');
if (itemEl) {
item = this.getComponent(itemEl.id.split(this.idDelimiter)[1]);
if (input) {
var inputEl = Ext.get(input),
isChecked = inputEl.getAttribute('checked');
if (isChecked) {
item = this.getComponent(itemEl.id.split(this.idDelimiter)[1]);
item.setTitle(item.title);
} else {
inputEl.dom.setAttribute('checked', 'checked');
}
}
if (item.disabled) {
return {
close: null,
item: null,
el: null
};
}
}
return {
close: e.getTarget('.x-tab-strip-close', this.strip),
item: item,
el: itemEl
};
}
Here's a working sample based on your code, hope it helps to solve your problem.
var tabContainer = tabPanel.getAt(0);
var customTitle = "hello";
tabContainer.tab.on('click', function(el,event) {
var target = event.target;
if( target.type == "checkbox" ) {
// If checkbox has just been checked
if( event.target.checked ) {
tabContainer.setTitle( '<input type="checkbox" checked />' + customTitle );
tabContainer.checked = true;
// If checkbox has just been unchecked
} else {
tabContainer.setTitle( '<input type="checkbox" />' + customTitle );
tabContainer.checked = false;
}
}
});

Extjs htmleditor wont set doctype and head tags

I am building a section in my app where you can send emails.
In order to do that, this user needs to paste a complete html content and preview it with the html editor in extjs.
The problem is that Extjs remove head and body and changing the doctype tag
have a look here, click on the buttons at the bottom: http://jsfiddle.net/LKJSm/
Ext.onReady(function () {
Ext.tip.QuickTipManager.init();
var top = Ext.create('Ext.form.Panel', {
items: [{
xtype: 'htmleditor',
name: 'htmlContent',
height: 300,
anchor: '100%'
}],
buttons: [{
text: 'Set doctype with head and body',
handler: function () {
top.down('htmleditor').setValue("<DOCTYPE /><head></head><body>body here</body>");
}
}, {
text: 'Alert Content',
handler: function () {
var editor = top.getForm().findField('htmlContent');
alert(editor.getValue());
}
}]
});
top.render(document.body);
});
here is a solution provided in Extjs forums: http://www.sencha.com/forum/showthread.php?146160-HTMLEditor-strips-dtd-head-and-body-tags
Ext.define('MyHTMLEditor', {
extend:'Ext.form.HtmlEditor',
alias: 'widget.myhtmleditor',
tagsToComment: ['!DOCTYPE', 'html', 'head', 'body'],
/**
* Pushing value to wysiwyg iframe loses dtd, html, head and body tags.
* Override hack to comment them out when pushing to iframe, and then uncomment
* them on the way back (see this.cleanHtml).
*/
pushValue: function() {
var me = this,
v;
if(me.initialized){
v = me.textareaEl.dom.value || '';
if (!me.activated && v.length < 1) {
v = me.defaultValue;
}
if (me.fireEvent('beforepush', me, v) !== false) {
///////////// change
for (var i=0;i<me.tagsToComment.length;i++) {
v = v.replace(RegExp('<(\s*\/?'+me.tagsToComment[i]+'.*?)>', 'ig'), '<!--$1-->');
}
/////////////
me.getEditorBody().innerHTML = v;
if (Ext.isGecko) {
// Gecko hack, see: https://bugzilla.mozilla.org/show_bug.cgi?id=232791#c8
me.setDesignMode(false); //toggle off first
me.setDesignMode(true);
}
me.fireEvent('push', me, v);
}
}
},
/**
* Uncomment the tags mentioned in pushValue
*/
cleanHtml: function(html) {
var me = this, i,
result = me.callParent(arguments);
for (i=0;i<me.tagsToComment.length;i++) {
result = result.replace(RegExp('<!--(\s*\/?'+me.tagsToComment[i]+'.*?)-->', 'ig'), '<$1>');
}
return result;
},
});
use of html tags are not allowed, in fact they are identified as thereat. if you want the tags to be displayed you need to change as follows
top.down('htmleditor').setValue("<DOCTYPE /> <head></head><body>body here</body>");
this will display the tags on the editor for now.
if you don't want them to show up on the editor you need to concatenate the tags when you pass it to the email client.

highcharts : set title on exporting

I'm looking a way to:
hide title on the HTML page result
show title on the highcharts graph when I export it (PDF,PNG,JPEG or print)
I don't know how to proceed. There is someone able to help me?
You can define this parameter in exporting.
http://api.highcharts.com/highcharts#exporting.chartOptions
http://jsfiddle.net/BdHJM/
exporting:{
chartOptions:{
title: {
text:'aaaaa'
}
}
},
put this function in your document ready function below is a code for changing highcharts print prototype and just for the patch or to make it work put rangeSelector option in your exporting and set it to false as mentioned below you can set it to your needs in future
Highcharts.wrap(Highcharts.Chart.prototype, 'print', function (proceed) {
var applyMethod = function (whatToDo, margin) {
this.extraTopMargin = margin;
this.resetMargins();
this.setSize(this.container.clientWidth , this.container.clientHeight , false);
this.setTitle(null, { text: 'SET TITLE HERE' :'});
this.rangeSelector.zoomText[whatToDo]();
$.each(this.rangeSelector.buttons, function (index, button) {
button[whatToDo]();
});
};
if (this.rangeSelector) {
var extraMargin = this.extraTopMargin;
applyMethod.apply(this, ['hide', null]);
var returnValue = proceed.call(this);
applyMethod.apply(this, ['show', extraMargin]);
this.setTitle(null, { text: '' });
} else {
return proceed.call(this);
this.setTitle(null, { text: '' });
this.yAxis[0].setExtremes();
} }
});
and in chart option set this (change it according to you need to, i am just putting my code for reference
)
exporting: {
scale: 1,
sourceWidth: 1600,
sourceHeight: 900,
chartOptions: {
rangeSelector: {
enabled: false
},
}

ExtJS4: this.ownerCt in initComponent function

Is there any way to access the parent component (via this.ownerCt) in the initComponent function?
While trying to access it via this.ownerCt, i found out that the ownerCt attribute is set after initComponent. So I do not know how i can hook in the initialization process of my component where i can change some parent's attributes.
I know this doesn't answer the question directly. I would have placed this in the comments to your question but I'm not allowed yet it would appear. If you are building breadcrumbs. I would look at extending the tab panel and creating a plugin for the Tab Bar that creates the kinda of navigation you want.
Ext.define('HOD.plugins.Breadcrumbs', {
// private
init : function(tabBar) {
tabBar.on('beforeadd', this.addIcons, this);
tabBar.on('beforeremove', this.handleTabRemove, this);
},
addIcons: function(tabBar, newTab, index, options) {
if (index > 0) {
newTab.iconCls = 'icon-arrow';
tabBar.items.each(function(tab) {
if (tab != newTab) {
tab.overCls = 'breadcrumbs-over'
}
});
}
},
handleTabRemove: function(tabBar, oldTab, options) {
var count = tabBar.items.getCount();
if (count > 1) {
var newTab = tabBar.items.getAt(count-2);
newTab.overCls = '';
newTab.removeCls('x-tab-breadcrumbs-over');
}
}
});
Then extend the tab panel so it uses the above plugin to style the tabs correctly.
Ext.define('HOD.view.GlobalNavigation', {
extend: 'Ext.tab.Panel',
border: false,
alias: 'widget.content',
requires: ['HOD.plugins.Breadcrumbs'],
tabBar: {
cls: 'breadcrumbs',
plugins: ['tabbarbreadcrumbs']
},
initComponent: function() {
this.on('tabchange', this.handleTabChange, this);
this.callParent(arguments);
},
push: function(tab) {
this.add(tab);
this.setActiveTab(tab);
},
pop: function() {
// Get the current cards;
var cards = this.getLayout().getLayoutItems();
if (cards.length > 1) {
this.setActiveTab(cards[cards.length-2]);
}
},
handleTabChange: function (tabPanel, newCard, oldCard, options) {
var cards = tabPanel.getLayout().getLayoutItems();
for (var i = (cards.length - 1); i > 0; i--) {
if (cards[i] !== newCard) {
this.remove(cards[i]);
} else {
break;
}
}
}
});
I've written up post about it here if you need more detail.
I would not recommend changing anything in the container from the inside element functions. Instead I would create an event in the element, fire that event and listen for it in the container.
This way your component will notify the container to do something, and container will do it itself.

jQuery UI Autocomplete: set active item

I am trying to micmic teh behaviour of a simple HTML SELECT element with jQuery Ui Autocomplete.
Is it possible to set the active item (move focus) on the open event? Basically, I am trying to mimic the selected="selected" option from a html select element - if the value in the field matches with one from the list, make that list item 'selected'.
Here's a jsfiddle of what you'e looking for: http://jsfiddle.net/fordlover49/NUWJr/
Basically, took the combobox example from jquery's website, and changed the renderItem functionality. In the example off of jqueryui.com's site, change:
input.data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.label + "</a>").appendTo(ul);
};
To:
input.data("autocomplete")._renderItem = function(ul, item) {
$item = $("<li></li>").data("item.autocomplete", item).append("<a>" + item.label + "</a>");
if (this.element.val() === item.value) {
$item.addClass('ui-state-hover');
}
return $item.appendTo(ul);
};
You can use the focus event to add/remove the active class. I like it more than the other ._renderItem code on this thread.
[...previous autocomplete options]
focus: function( event, ui ) {
// Remove the hover class from all results
$( 'li', ui.currentTarget ).removeClass('ui-state-hover');
// Add it back in for results
$( 'li',ui.currentTarget ).filter(function(index, element) {
// Only where the element text is the same as the response item label
return $(element).text() === ui.item.label;
}).addClass('ui-state-hover');
},
[next autocomplete options...]
Well, I finally figured out the answer with the help of a friend.
$('input[data-field=vat_rate]', view.el).autocomplete({
source: function (request, response) {
response(your_source_array);
},
minLength: 0,
open: function (event, ui) {
var term = ui.item.value;
if (typeof term !== 'undefined') {
$(this).data("autocomplete").menu.activate(new $.Event("mouseover"), $('li[data-id=' + term + ']'));
}
}
}).click(function () {
if ($(this).autocomplete('widget').is(':visible')) {
$(this).autocomplete('close');
} else {
$(this).autocomplete('search');
}
}).data("autocomplete")._renderItem = function (ul, item) {
var listItem = $("<li></li>")
.data("item.autocomplete", item)
.attr("data-id", item.id)
.append('<a>' + item.label + '</a>')
.appendTo(ul);
};
Here's the JSBin for it: http://jsbin.com/unibod/2/edit#javascript
Works perfect! :)

Resources