Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mask to inputText #791

Merged
merged 2 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# rather than c:\dir1\dir2 to refer to paths -- Java thinks a single backslash
# is an escape character followed by a control character.
#########################################################################################################
VERSION=1.1.1
VERSION=1.1.2-SNAPSHOT
# RELEASE-STATUS - SNAPSHOT , beta1, rc1 ...
# or don't remove the property but just leave it blank for a Final RELEASE :
# RELEASE-STATUS=
Expand Down
1 change: 1 addition & 0 deletions gradleResources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from 'staticResources/js/fullcalendar.min.js'
from 'staticResources/js/fullcalendar-lang-all.js'
from 'staticResources/js/jquery.blockUI.js'
from 'staticResources/js/jquery.inputmask.bundle.min.js'
from 'staticResources/js/jquery.scrollUp.min.js'
from 'staticResources/js/jquery.minicolors.min.js'
from 'staticResources/js/moment.min.js'
Expand Down
11 changes: 11 additions & 0 deletions gradleResources/staticResources/js/jquery.inputmask.bundle.min.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.bootsfaces</groupId>
<artifactId>bootsfaces</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
<name>BootsFaces</name>
<description>TheCoder4EU</description>
<url>http://www.bootsfaces.net</url>
Expand Down Expand Up @@ -74,7 +74,7 @@

<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/bootsfaces/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class C {
/**
* BootsFaces Library Constants
*/
public static final String BSFVERSION="1.1.1";
public static final String BSFVERSION="1.1.2-SNAPSHOT";
public static final String BSFRELEASE_STATUS=""; //SNAPSHOT or empty String (for a final RELEASE)
public static final String BSFCOMPONENT= "net.bootsfaces.component";
public static final String BSFLAYOUT = "net.bootsfaces.layout";
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/net/bootsfaces/component/inputText/InputText.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import javax.el.ValueExpression;
import javax.faces.component.FacesComponent;

import net.bootsfaces.C;
import net.bootsfaces.beans.ELTools;
import net.bootsfaces.component.ajax.IAJAXComponent;
Expand All @@ -42,6 +40,10 @@
@FacesComponent(InputText.COMPONENT_TYPE)
public class InputText extends InputTextCore implements IHasTooltip, IAJAXComponent, IResponsive, IResponsiveLabel {

protected enum PropertyKeys {
mask
}

private String renderLabel = null;

/**
Expand Down Expand Up @@ -154,4 +156,26 @@ public void setTypeaheadValues(Object _typeaheadValues) {
setTypeahead(true);
super.setTypeaheadValues(_typeaheadValues);
}

/**
* Returns input mask.
*
* @return Input mask.
*/
public String getMask() {
return (String) getStateHelper().eval(PropertyKeys.mask);
}

/**
* Sets input mask and triggers JavaScript to be loaded.
*
* @param mask Input mask to set.
*/
public void setMask(String mask) {
if (mask != null && !mask.isEmpty()) {
AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "js/jquery.inputmask.bundle.min.js");
}
getStateHelper().put(PropertyKeys.mask, mask);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;

import net.bootsfaces.C;
import net.bootsfaces.component.ajax.AJAXRenderer;
import net.bootsfaces.component.inputSecret.InputSecret;
Expand Down Expand Up @@ -285,7 +283,34 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
}
rw.endElement("script");
}
encodeMask(context, inputText, fieldId, rw);
}

/**
* Add script to enable the input mask.
* See https://github.com/RobinHerbots/Inputmask.
*
* @param context
* @param inputText
* @param fieldId
* @param rw
*
* @throws IOException
*/
protected void encodeMask(FacesContext context,
InputText inputText,
String fieldId,
ResponseWriter rw) throws IOException {
if (inputText.getMask() != null && !inputText.getMask().isEmpty()) {
rw.startElement("script", inputText);
rw.writeText("Inputmask(\"", null);
rw.writeText(inputText.getMask().replace("\"", "\\\""), null);
rw.writeText("\").mask(document.getElementById(\"", null);
rw.writeText(fieldId, null);
rw.writeText("\"));", null);
rw.endElement("script");
}
}

private String addOption(String options, String newOption) {
if (options.length() > 0) {
Expand Down
Loading