Last active
December 19, 2015 09:29
-
-
Save canthony/5933451 to your computer and use it in GitHub Desktop.
Snippets of a simple Vaadn 7 component extension that should ensure numeric-only characters entered in a text field, using jQuery + the autoNumeric jQuery plugin. autoNumeric is very flexible - I haven't done any configuration, but it's not very difficult to do.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An extension used to configure a TextField to allow only numbers, using the autoNumeric jQuery plugin. | |
* | |
* Proof of concept, really : have not implemented any server side configuration. | |
* <p/> | |
* | |
* @author Charles | |
* @see <a href="http://www.decorplanit.com/plugin">autoNumeric site</a> | |
* @see <a href="https://jquery.org">jQuery site</a> | |
*/ | |
@JavaScript({"js/jquery-1.8.3.min.js", "js/autoNumeric-1.9.6.js"}) | |
public class AutoNumericExtension extends AbstractExtension { | |
private static final long serialVersionUID = 8976627065068505781L; | |
public void extend(AbstractTextField target) { | |
super.extend(target); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Connect(AutoNumericExtension.class) | |
public class AutoNumericExtensionConnector extends AbstractExtensionConnector { | |
private static final long serialVersionUID = 6875456486902748081L; | |
protected transient VTextField textFieldWidget; | |
@Override | |
protected void extend(ServerConnector target) { | |
textFieldWidget = (VTextField) ((ComponentConnector) target).getWidget(); | |
initAutoNumeric(textFieldWidget.getElement()); | |
} | |
protected static native void initAutoNumeric(Element element) | |
/*-{ | |
$wnd.jQuery(element).autoNumeric('init'); | |
}-*/; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextField x = new TextField("Numeric Thing"); | |
new AutoNumericExtension().extend(x); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment