Vlada
Vlada

Reputation: 667

How to enter text in uppercase?

I need enter text only at uppercase. How can I do it in vaadin with TextField? I need that text is really uppercase not only visualy using styles....

Upvotes: 1

Views: 8983

Answers (6)

Theek
Theek

Reputation: 29

I would say ..

<input id="yourid" style="**text-transform: uppercase**" type="text" />

Upvotes: -1

Budi
Budi

Reputation: 1

in event keyreleased you write

private void jTxtNoRincKeyReleased(java.awt.event.KeyEvent evt)
{
    // TODO add your handling code here:
    jTxtNoRinc.setText(jTxtNoRinc.getText().toUpperCase());
}

jTxtNoRinc : Component's Name

it's simple

Upvotes: 0

Arun
Arun

Reputation: 1

Use a converter. Just like you would convert a field from String to Int using the StringToIntConverter, you could try using the StringToUpperCaseStringConverter and then bind it.

Upvotes: 0

Juan Rojas
Juan Rojas

Reputation: 8861

Well this is my try:

code

public class UpperTextField extends TextField {


public UpperTextField() {
    addStyleName("upper-case");
}

@Override
protected String getInternalValue() {
    return super.getInternalValue() != null ? super.getInternalValue().toUpperCase() : super.getInternalValue();
}

}

css

.upper-case{
text-transform: uppercase;
}

Upvotes: 1

Yury
Yury

Reputation: 664

The easiest way to solve your problem is wroten by "user810595". But if your do not want to use custom styles in your application you can use this code:

    final TextField field = new TextField();
    field.setImmediate(true);

    field.addListener(new TextChangeListener() {
        @Override
        public void textChange(TextChangeEvent event) {
            String text = event.getText();
            field.setValue(text.toUpperCase());

                    //TODO: do some actions if needed
        }
    });

Upvotes: 3

Benjamin Brandmeier
Benjamin Brandmeier

Reputation: 754

An easy way to achieve this is to set the style and change the string to uppercase by yourself.

Here's the VAADIN code:

TextField donut = new TextField();
donut.setStyleName("upMeBro");
this.addComponent(donut);

Set the css file like this:

.v-textfield-upMeBro {
    text-transform: uppercase;
}

After a event is fired (User typed in text, Button is clicked, etc.) you can easily modify the string to uppercase with native java:

System.out.println(donut.getValue().toString().toUpperCase());

Upvotes: 5

Related Questions