Skip to content

Instantly share code, notes, and snippets.

@canthony
Last active December 19, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canthony/5933451 to your computer and use it in GitHub Desktop.
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.
/**
* 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);
}
}
@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');
}-*/;
}
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