Repository: wicket Updated Branches: refs/heads/master 74ba1a8ab -> 13a763eda
Add 'minlength' to <input> or <textarea> if Size.min() is bigger than 0 Fixes #144 Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/13a763ed Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/13a763ed Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/13a763ed Branch: refs/heads/master Commit: 13a763edae1e262296d9b240a65fbbfe2d16af6e Parents: 74ba1a8 Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org> Authored: Sat Feb 6 15:33:47 2016 +0100 Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org> Committed: Sat Feb 6 15:33:47 2016 +0100 ---------------------------------------------------------------------- .../wicket/bean/validation/SizeTagModifier.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/13a763ed/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/SizeTagModifier.java ---------------------------------------------------------------------- diff --git a/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/SizeTagModifier.java b/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/SizeTagModifier.java index 1795dc4..9f2aa67 100644 --- a/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/SizeTagModifier.java +++ b/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/SizeTagModifier.java @@ -6,8 +6,8 @@ import org.apache.wicket.markup.ComponentTag; import org.apache.wicket.markup.html.form.FormComponent; /** - * A tag modifier that adds the {@code maxlength} attribute to the {@code input} tag with the max - * value from the {@link Size} constraint annotation. + * A tag modifier that adds the {@code maxlength} and {@code minlength} attributes to the {@code input} + * and {@code textarea} tag with the max/min value from the {@link Size} constraint annotation. * * @author igor * @@ -17,9 +17,19 @@ public class SizeTagModifier implements ITagModifier<Size> @Override public void modify(FormComponent<?> component, ComponentTag tag, Size annotation) { - if ("input".equalsIgnoreCase(tag.getName())) + if (hasLengthAttribute(tag.getName())) { tag.put("maxlength", annotation.max()); + + if (annotation.min() > 0) + { + tag.put("minlength", annotation.min()); + } } } + + protected boolean hasLengthAttribute(String tagName) + { + return "input".equalsIgnoreCase(tagName) || "textarea".equalsIgnoreCase(tagName); + } }
