Highlight default button in ExtJS (3.x) MessageBox - button

is there an Ext-sanctioned way to highlight the default button (the one triggered by pressing Enter) in Ext.MessageBox?
Please note that I do not want to do that by focusing the button when the MessageBox is shown (in case of a "prompt" dialog I want the input element to have focus).
I know I can do that by adding a custom class to the button element but ... maybe there is a better and more Ext-like way of doing this?
Thanks.

In ExtJs 4 you can set the default button as follows:
Ext.MessageBox.defaultButton = buttonIndex;
Where 'buttonIndex' is the index of the button on the dialog. You need to do this before you call Ext.MessageBox.Show.

In short... no. Ext currently provides no method of highlighting a button in any of the Ext.MessageBox components, not via a config option anyway.
There are ways however, depending on the scenario. For example, if you're using Ext.MessageBox.show() (which you can actually use for all message boxes), then you can do something like...
new Ext.Msg.show({
title: 'Test',
msg: 'A sample message box with a button marked as default',
buttons: { ok: '<b>Submit</b>', cancel: 'Cancel' },
fn: function(btn) {
if(btn == 'ok') {
//do something
}
},
icon: Ext.Msg.WARNING
}
All we've done is add <b> tags to one of the buttons in our config, this would show it in bold obviously.
The other way that you've mentioned is to add a custom class and mark the button in a colour of text, you could even just add the class like we did with the <b> tags above to make it easier..
buttons: { ok: '<span class="highlighted-option">Submit</span>', cancel: 'Cancel' },
Other than this style of approach, or without extending the Ext.MessageBox class, there's no other way to achieve this.

Jaitsu has the best answer, but in case this might be useful to somebody else... here is a way to do that with styles.
The same trick can be applied to any other button (like: Window buttons).
Add this to your css:
.x-btn-default td.x-btn-mc {
outline: 1px dotted black;
}
Then define buttons like this:
...
,buttons: [
{
text: 'Ok',
,handler: handleFn
,cls: 'x-btn-default'
},{
text: 'Cancel',
,handler: handleFn
}
]
,...

Related

Ionic 4 - How to change font-size of button inside a Toast

I'm building an app with Ionic 4 + React.
Using a toast component when the user delete an element to show the message "deleted successfully", but adding a button inside to give the possibility to undo the action.
I need to change the font-size of that button, but almost all the toast DOM is inside a shadow-root:
Reading articles like this, I understand that everything inside shadow-root it can't be styled by css selectors and must be styled using CSS4 Ionic variables.
But I can't find a css variable to change de font-size of the button, this is what Ionic does (not with variables):
Read some people that said that could work with a custom class, I already tried that but without any luck:
Toast component:
<IonToast
cssClass="e7-toast"
isOpen={showToastDeshacer}
color="dark"
onDidDismiss={() => setShowToastDeshacer(false)}
message="Deleted successfully"
position="bottom"
buttons={[
{
text: 'Undo',
role: 'cancel',
handler: () => {
console.log('Undo clicked');
}
}
]}
/>
CSS:
.e7-toast .toast-button-inner {
font-size: 44px!important;
}
Anyone with more experience in Ionic 4 knows a way to change the font-size of that button?
Thanks!
you can change the shadow dom by using ::part.
There is the article for your reference:
https://css-tricks.com/styling-in-the-shadow-dom-with-css-shadow-parts/

Extjs 5: how to make two panel with different style

In a sencha app, I want to create two or more "Panel" in the same page, but with different Style.
Panel_1.js:
Ext.define("MyApp.view.Panel_1",{
extend:'Ext.panel.Panel',
title:'Panel 1 title",
//some try
componentCls:'panel_1',
cls:'panel_1'
...
});
Panel_2.js:
Ext.define("MyApp.view.Panel_2",{
extend:'Ext.panel.Panel',
title:'Panel 2 title",
componentCls:'panel_2'
});
I add these two panels in one page, eg. the "center" of mainview. Add for css file with css class panel_1 and panel_2. But does not work.
how can I set these two panel with different Title, Background color, color, border, and so on.
Add the same question, I want different Button, eg. Blue Button with yellow text, red Button with white text, in a same toolbar.
I try override the extjs css class, eg. x-panel-body . You know, all compoent will be changed. That is not what I want.
It's hard to tell what you're having a hard time with. What you seem to be trying to do does work. I'll just provide a simple example, see https://fiddle.sencha.com/#fiddle/ecd
The easiest way is to add a cls to your panel, then you can use CSS to apply only within those classes. You can also add cls to items inside of your component. Also, Ext has some classes it already applies so you can use them (x-body, x-header for Ext.panel.Panel). The following example shows you how to scope your .x-header definitions so they only apply to your class
JavaScript
Ext.define("MyApp.view.Panel_1",{
extend:'Ext.panel.Panel',
title:'Panel 1 title',
cls:'panel_1',
html: 'Here I am',
buttons: [{text: 'OK', cls: 'ok'}, {text: 'Cancel', cls: 'cancel'}]
});
Ext.define("MyApp.view.Panel_2",{
extend:'Ext.panel.Panel',
title:'Panel 2 title',
cls:'panel_2',
html: 'Here I am again',
buttons: [{text: 'OK', cls: 'ok'}, {text: 'Cancel', cls: 'cancel'}]
});
CSS
.panel_1 .x-header{
background-color: blue;
}
.panel_1 .ok{
background-color: green;
}
.panel_2 .x-header{
background-color: yellow;
}
.panel_2 .cancel{
background-color: red;
}
Most typically, you would extend your sass resources to create custom classes for your both Panels (or at least for the one you wish to change).
You could do it with the Sencha Architect, which has a 30 day trial period.
The trick would then be to add a ui tag, that would then be added to your generated class name
Ext.define("MyApp.view.Panel_2", {
ui: 'black'
});
would then be generated with a class called like
.panel-default-black
for this class you could then create your sass for all internal elements
sass/component.css would then for eg contain
.panel-default-black {
background-color: black;
color: #ffffff;
.panel-default-header {
background-color: $some-predefined-value-in-another-sass-file;
}
}
another option would be to use the UI-label, like:
#include extjs-panel-ui(
$ui-label: 'black',
$ui-background: black;
$ui-color: white;
$ui-header-background-color: blue;
);
After compiling the theme, you would then see the changes between the 2 panels.
More info, you could find on the site of Sencha
Yet another none recommended way, would be to use the style tag, and to directly give your style for your panel, but that is not recommended to use

jQuery validate using custom div and css

I have a div that I want login error messages to go into:
<div id="loginMessage" class="blankBox"> </div>
When there are validation errors, I want the class of this div to be 'errorBox'. When there are no validation errors, I want the css to be 'blankBox'.
And I have the following jQuery validation:
<script>
$(function() {
$("#loginForm").validate({
rules: {
username: "required",
password: "required"
},
messages: {
username: "Please enter a username",
password: "Please enter a password",
},
errorLabelContainer: "#loginMessage",
wrapper: "li",
highlight: function(element) {
$(element).addClass('errorBox');
},
unhighlight: function(element) {
$(element).removeClass('errorBox');
},
});
});
</script>
Unfortunately, what's happening is that the errorBox css is being applied to the input fields. ?!? I cannot get this to work.
Any ideas?
Based on your comment from another answer:
"I want the css to be neutral until errors appear in it, and then reset
to neutral when errors leave it."
I have no idea what "neutral" means, but by default when all errors leave the container, the plugin makes the container "hidden". In other words, all that matters is the style of the container when it contains errors since it's only going to be seen when there are errors inside of it. Otherwise, it's simply hidden. To achieve this initial state, set the style to display: none;. You may also set your other properties for when it will be seen with errors. (refer to the jsFiddle example).
Despite the other answers, errorPlacement is no good in this scenario. It's only used for placing the individual messages. It has nothing to do with the messages inside the error container.
I also removed your highlight and unhighlight callback functions as those are fired off on a field-by-field basis and also would have nothing to do with your error container. (You've also broken their default functionality by over-riding them with your own functions.)
DEMO: http://jsfiddle.net/6dCB7/
jQuery:
$(document).ready(function () {
$('#loginForm').validate({ // initialize the plugin
errorLabelContainer: "#loginMessage",
wrapper: "li",
rules: {
// your rules
}
});
});
HTML:
<div id="loginMessage"></div>
<form id="loginForm">
....
</form>
CSS:
#loginMessage {
display: none;
/* also set the properties for when it displays with errors */
}

Make checkbox look like button

In my web app (c#/MVC3), I have a huge set of checkboxes in a table. Rather than a table of checkboxes, I'd like for it to look like a wall of toggle buttons. To the user I want it to look like a wall of buttons and when they click one it is 'checked' and the button changes color.
I wasn't sure if there was CSS that could make a checkbox do this (look like a button and change colors on check rather than show a check mark), or if I would have to use some combination of buttons and javascript/jquery and hidden checkboxes or what.
The jQuery UI Button widget can handle that:
http://jqueryui.com/button/#checkbox
Yes, it is definitely possible to do what you want with pure CSS.
I think you should check out the jsFiddle mentioned on this question.
Radio buttons are generated by the operating system and cannot be easily styled.
If you wany something different you need to generate it using CSS/images and JavaScript.
First of all, I'd actually avoid doing this for usability concerns but if you still want to then read on.
This is actually quite tricky to achieve but it is possible. My solution avoids the need to assign individual IDs to your check-boxes.
Essentially, you will need an image sprite for the "on" and "off" states which you will position with the CSS background-position property, using a toggle class. Then, the following jQuery will allow you to not only swap the image state, but also confirm the respective checkbox as checked or unchecked for use of the form. Do note, that the "actual" checkbox is hidden from view but the functionality remains.
<form>
<input type="checkbox" class="custom" />
</form>
<style type="text/css">
.checkbox {
clear:left;
float:left;
background:url('your_image');
background-position:top;
width:20px;
height:20px;
display:block;
}
.toggled {
background-position:bottom !important;
}
</style>
$(document).ready(function () {
var checkboxes = $('form .custom'),
custom = $('<span></span>').addClass('checkbox');
checkboxes.before(custom);
checkboxes.css('visibility', 'hidden');
$('.checkbox').click(function () {
$(this).toggleClass('toggled');
var isChecked = $(this).next(':checkbox');
var value = isChecked.prop('checked') ? 'true' : 'false';
if (value == 'false') {
isChecked.prop('checked', true);
} else {
isChecked.prop('checked', false);
}
});
});
You will, of course, have to edit the CSS to suit your exact needs. I hope this helps as this task was deceptively non-trivial.

jQueryUI.dialog: override single css style property?

jQuery UI themes are nice they apply to the entire document, however I have some cases where the style of the dialog such as the title bar colour must be changed.
In my jQuery UI css, the titlebar is coded:
.ui-dialog .ui-dialog-titlebar { padding: .4em 1em; position: relative; }
Here's my javascript:
var $AlertDialog = $('<div"></div>')
.dialog({
autoOpen: false,
title: 'Alert Message',
buttons: {Ok: function() {$( this ).dialog( "close" );}}
});
function Alerter(cTxt)
{
$AlertDialog.html(cTxt);
$AlertDialog.css('ui-dialog-titlebar','color: red');
$AlertDialog.dialog('open');
};
Alerter() is then called as a substitute for alert().
Accessing and altering the color property of 'ui-dialog-titlebar' has no effect.
Lots of reading preceded this question. Seems others have had similar issues, but not specific to jQuery UI.
How can this be done?
Update:
Thanks to a good hint, I did this:
$AlertDialog.dialog('open');
$("#.ui-dialog .ui-dialog-title").css('color','red');
$("#.ui-dialog .ui-dialog-title").css('background-color','orange');
Works. But acceptable practice?
My suggestion would be to not use the .ui-dialog selector as there may be more than one dialog on a page. You can traverse to the title bar.
...
$AlertDialog.html(cTxt);
// might as well use the theme since its part of jquery ui
$AlertDialog.prev().addClass("ui-state-error");
$AlertDialog.dialog('open');
Firstly,
According to documentation .css() takes property as param.
It seems you are trying changing ui-dialog-titlebar. Instead try this:
...
function Alerter(cTxt)
{
$AlertDialog.html(cTxt);
$AlertDialog.dialog('open');
$(".ui-dialog .ui-dialog-title").css('color','red');
$(".ui-dialog .ui-dialog-title").css('background-color','orange');
//Assuming you want to change header color only
//see the theming structure at http://jqueryui.com/demos/dialog/#theming
};

Resources