package cz.metacentrum.perun.wui.registrar.widgets.items.validators;

import cz.metacentrum.perun.wui.registrar.widgets.items.Radiobox;
import org.gwtbootstrap3.client.ui.constants.ValidationState;

/**
 * @author Ondrej Velisek <ondrejvelisek@gmail.com>
 */
public class RadioboxValidator extends PerunFormItemValidatorImpl<Radiobox> {

	@Override
	public boolean validateLocal(Radiobox radiobox) {

		if (radiobox.isRequired() && isNullOrEmpty(radiobox.getValue())) {
			setResult(Result.EMPTY);
			radiobox.setStatus(getTransl().cantBeEmpty(), ValidationState.ERROR);
			return false;
		}

		radiobox.setStatus(ValidationState.SUCCESS);
		return true;
	}

}
@@ -63,16 +63,109 @@
 ators;%0A%0A
+import com.google.gwt.regexp.shared.MatchResult;%0Aimport com.google.gwt.regexp.shared.RegExp;%0A
 import c
@@ -222,16 +222,16 @@
 diobox;%0A
-
 import o
@@ -679,16 +679,478 @@
 e;%0A%09%09%7D%0A%0A
+%09%09String regex = radiobox.getItemData().getFormItem().getRegex();%0A%0A%09%09if (regex != null && !regex.equals(%22%22)) %7B%0A%0A%09%09%09RegExp regExp = RegExp.compile(regex);%0A%09%09%09MatchResult matcher = regExp.exec(radiobox.getValue());%0A%09%09%09boolean matchFound = (matcher != null); // equivalent to regExp.test(inputStr);%0A%09%09%09if(!matchFound)%7B%0A%0A%09%09%09%09setResult(Result.INVALID_FORMAT);%0A%09%09%09%09radiobox.setStatus(getErrorMsgOrDefault(radiobox), ValidationState.ERROR);%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%0A
 %09%09radiob
@@ -1207,9 +1207,10 @@
 ue;%0A%09%7D%0A%0A
-
 %7D
+%0A

Allow regex check on radio buttons on registration forms