Textfield for Scientific notation

Is there a TextField addon that accepts numbers only INCLUDING scientific notation (eg. 0.23e10)?

I think you can accomplish that with the
CSValidation add-on
.

Wonderful. It works great!

One issue I noticed though, if I edit a field by adding invalid character (eg. old field is “1.23e10”, I type 1.5w10) I get weird behavior if I enter invalid characters (see attached screen shots: Original → afterEdit → afterExit → afterSecondEdit).

Here is my code:

    private static Field<String> createDoubleField(String label)
    {
        TextField tf = new TextField(label);
        tf.setNullRepresentation("");
        tf.setImmediate(true);
        String regexp = "[-+]
?[0-9]
*\\.?[0-9]
+([eE]
[-+]
?[0-9]
+)?";
        CSValidator doubleValidator = new CSValidator();
        doubleValidator.extend(tf);
        doubleValidator.setRegExp(regexp);
        doubleValidator.setPreventInvalidTyping(false);
        doubleValidator.setErrorMessage("Must be a number");
        return tf;
    }

Is there a way to prevent the field from reverting? Or to manually clear the error message? Or prevent the bad character from being added to the field altogether? (I am using validator.setPreventInvalidTyping(false) becaue I found setting it to true will completely clear the field on exit which is an undesired behavior.)
15626.png
15627.png
15628.png
15629.png

That’s odd. Perhaps there’s a regression, it looks like it adds a second element for the error message, but before the field. That should not be possible. I’ll have to inspect that more closely when I have time. I hope you can find a workaround meanwhile. What does Firebug say about the HTML structure when the problem occurs?

Oh, which browser are you using? CSValidator is completely untested with IE, only Firefox and Chrome are tested.

I’m using Chrome. I didn’t look at the inspector as I wasn’t sure of the ‘correct’ result. However, the behavior is easily reproducible .

I got around the issue by setting the error message to null. My converter already throws an exception during validation and that that causes the little validation error tooltip to show up. This is good enough for me for now. Thank you very much for your help.