Textfield text in InteractionDialog only shown when TextField has focus - codenameone

In an InteractionDialog of mine there is a TextField. I set the TextField style to a UIID defined in CSS. The TextField background is shown but not the text inside it
although
System.err.println("The textfield contains " + nameTf.getText());
prints the expected text and the foreground color is 0 as expected. The text is only shown when I press inside the TextField but as soon as I press outside it disappears as shown below :
No EDT violation appears in the console.
The code used is the following :
// Opens a dialog to input the name
nameButton.addActionListener((evt) -> {
InteractionDialog nameDialog = new InteractionDialog();
nameDialog.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));
// Hint for the user
SpanLabel hintLabel = new SpanLabel("Indiquer un nom");
hintLabel.setTextUIID(hintStyleName);
TextField nameTf = new TextField(
chosenAlarm.name.get() == null ? "Ma destination préférée" : chosenAlarm.name.get()
);
nameTf.setUIID(textFieldStyleName);
System.err.println("The textfield colour is " + nameTf.getUnselectedStyle().getFgColor());
// Validate text button
Button validateNameButton = new Button("Valider >");
validateNameButton.setUIID("ValidateButton");
Container nameButtons = BoxLayout.encloseX(validateNameButton);
validateNameButton.addActionListener((e) -> {
// ...
});
nameDialog.addComponent(BorderLayout.CENTER, nameTf);
nameDialog.addComponent(BorderLayout.NORTH, hintLabel);
// The buttons will be centered
nameDialog.addComponent(BorderLayout.SOUTH, BorderLayout.centerCenter(nameButtons));
// Shows the dialog in the center of the screen
nameDialog.showPopupDialog(nameButton);
});
So it seems that whenever the TextField looses focus the text disappears. What should I do to show the text contained in the TextField even when the user does not press inside the TextField ?
Please note : the screen captures hide some elements since the app is Top Secret NSA Level ;-).
Any help appreciated,

Actually the issue was coming from the css style where I set the opacity to 255 (like in the theme designer with transparency). It had to be set to a value between 0 and 1.0 indeed.
MyTextFiledStyle {
color: #000000;
background-color: #ffffff;
text-align: left;
opacity: 1.0; /*NOT 255 */
font-family: "native:MainLight";
}

Related

React js window.print freezes the page

In my project using React with Typescript I am trying to print a div with some data.
Basicaly This div is in a modal, I gave it an id (id='printablediv'). Then when you press print on the modal I run this function :
const Print = () => {
let printContents = document.getElementById('printablediv')?.innerHTML!;
let originalContents = document.body.innerHTML;
document!.body!.innerHTML! = printContents;
window.print();
document.body.innerHTML = originalContents;
setIsModalOpen(false)
}
Then problem is that when I click print and the print page opens and I print the div, after that the page freezes. and I cant do anything. I have to reload the page. Even if i don't print and press cancel, it still freezes. Has anyone encountered with problem?
I am trying not to use a library such as react-to-print.
Edit:
This is where i call the Print function:
<TicketModal
isOpen={isTicketModalOpen}
onAnulla={onCloseTicketModal}
onPrint={Print}
code={createResponseCode}
pin={createResponsePin}
id={user.uid}
currency={createResponseCurrency}
amount={createResponseAmount}
/>
the onPrint is the prop connected to the modal button
<Button size="lg"
variant="primary"
className='ticket-modal-card__button'
onClick={onPrint}
>
Print Ticket</Button>
I found the solution.
Apparently the problem is I'm removing the original content, and then replacing it with new, different content, so all the event listeners and metadata react had attached to the original content is lost. innerHTML doesn't include those things (setting innerHTML is probably never what you actually want to do in any situation).
To print just part of a page, I set up a print stylesheet that changes the styling of your page when printing, and not change the HTML itself.
.printme {
display: none;
}
#media print {
.no-printme {
display: none;
}
.printme {
display: block;
}
}
This way I can Display and hide everything I want and print only the part I need.

react-modal scroll top when open

I use react-modal to create a open modal form (similar create post modal form facebook).
My expect:
When modal is open: scrollbar of window still show but thumb disabled (user can't scroll)
When modal is close: scrollbar of window show and thumb show.
My problem:
When modal is open, scrollbar always on top (top = 0). I know because my css body { position: fixed } but I want modal look like my expect
Here is my codesandbox for my problem: https://codesandbox.io/s/scroll-modal-form-rw2sf
Sorry about my bad english and thanks for your help.
I set the style of class ReactModalPortal and adjust the z-index. In addition remove the style of body. There is a sandbox
/* index.css */
.ReactModalPortal {
height: 100%;
width: 100%;
position: absolute;
top: 0;
z-index: -1;
}
// App.js
...
const portal = document.querySelector(".ReactModalPortal");
portal.style.zIndex = 0;
...
const portal = document.querySelector(".ReactModalPortal");
portal.style.zIndex = -1;
Maybe it is not as your expectation, but you could modify it.

how to disable ion-item in ionic with angularJS?

I have many ion-items on my screen. I want to disable them every times i click a + icon my screen which blurs the screen and I want to disable all the clicks at that time how can i do that?
For you to blur the screen when you click a button, you can just use a empty div which can cover the height and width of the screen, and using ng-if you can toggle the div programmatically.
In html :
<div class="mr-blur" ng-if="toggle"></div>
In CSS :
.mr-blur{
height : 100vh;//full viewport height
width : 100vw;//full viewport width
background-color : white;//color of the overlay
opacity : 0.6;//to show a little bit of the iactive screen
z-index : 9999!important; //To put it on top of all elements
}
In JS :
$scope.plusButton = function(){ //function to be called when plus button is clicked
$scope.toggle = !$scope.toggle;//
}

Event propagation does not happen like standard html

I know that react uses its own synthetic implementation of events. However it appears to me that they are not exactly like standard html and this is a problem. In my case I have a checkbox that is a sibling of some img tags. There are two img tags, one for representing checked and another unchecked. I have some css styling that does a display none when the checkbox is in an unchecked state. Trying to get this html/css working with react is hard. It appears that the click event is not propagating onto the checkbox sibling with a react component, although it works from standard html. Note as there's some confusion I know that the non-react version of this is using css and not events. But I'm trying to implement a react evented version of the same thing, and was expecting normal html event propagation behavior--which I'm not seeing. Also note the checkbox is a sibling of the label. It's also transparent, so the user never actually clicks on the checkbox they click on the img tags.
.checkbox-image input[type="checkbox"] + label img.selected {
display: none;
}
.checkbox-image input[type="checkbox"] + label img.unselected {
display: block;
}
<div class="checkbox-image"><input id="portfolio-standard-dev" type="checkbox" data-name="PortfolioStandardDeviation"><label for="mp-chart3"><img class="unselected" src="/images/img-843599.png"><img class="selected" src="/images/img-1b9f30.png"><span>Portfolio Standard Deviation</span></label></div>
CSS has nothing to do with events. An event propagation cannot impact your styles.
You have to handle when the user check/uncheck the checkbox and manually update the class of the image.
Or you can try the following pure CSS:
.checkbox-image input[type="checkbox"]:checked + label img {
display: none;
}
.checkbox-image input[type="checkbox"] + label {
display: block;
}

Angularjs/Bootstrap - how to create a stateless button

Using Bootstrap and Angularjs I'd like to create a button that doesn't ever appear to be "active". I'd like the button to darken slightly when the mouse is over it, and I'd like it to darken further when it's clicked. When the mouse leaves the button, however, I'd like it to return to its original appearance.
Semantically, I'm using the button to "reset" part of my app. I want to execute some code when it's clicked. After it's been pressed, though, it doesn't make sense for the button to remain in a "depressed" state.
Here's a live example.
Any ideas?
Alternatively you could use the ng-mouseenter and ng-mosueleave directives.
For example:
<div ng-app="ButtonApp">
<div ng-controller="MainCtrl">
<button ng-class="buttonClass"
ng-mouseenter="onMouseEnter()"
ng-mouseleave="onMouseLeave()"> Click Me!
</div>
</div>
And in your controller:
var app = angular.module('ButtonApp',[]);
app.controller('MainCtrl', ['$scope',function($scope){
var defaultButtonClass = ['btn','btn-foxtrot'];
$scope.buttonClass = defaultButtonClass;
$scope.onMouseEnter = function(){
$scope.buttonClass = ['btn','btn-bravo'];
};
$scope.onMouseLeave = function() {
$scope.buttonClass = defaultButtonClass;
}
}]);
You can see my JSFiddle.
To generate the button colors you could use something like Beautiful Buttons for
Twitter Bootstrappers.
I'd give it another class, say btn-reset and add the following CSS.
// the order of these two is also important
.btn-reset:hover{
background-color: Dark !important;
}
.btn-reset:active{
background-color: Darkest !important;
}
// you need this to reset it after it's been clicked and released
.btn-reset:focus{
background-color: Normal !important;
}
It's working here http://plnkr.co/edit/QVChtJ8w70HXmyAaVY4A?p=preview
The issue is that the :focus pseudo class has a darker colour than the standard button so after it's been clicked it still has focus so still has the darker colour, if you want to stick with the standard colours you can just add a new selector for the :focus pseudo class.

Resources