Validate the type selection in the same way as the other fields.

Removed the client-side validation (HTML required attribute) and rely on server-side validation with a red feedback message instead.
This commit is contained in:
Andreas Svanberg 2025-01-10 10:21:02 +01:00
parent 5ca13d5d32
commit 57e6f5c1cc

@ -18,6 +18,7 @@ import org.apache.wicket.model.*;
import org.apache.wicket.model.util.ListModel;
import org.apache.wicket.model.util.SetModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.value.IValueMap;
import org.apache.wicket.validation.validator.StringValidator;
import se.su.dsv.scipro.components.*;
import se.su.dsv.scipro.generalsystemsettings.GeneralSystemSettings;
@ -187,7 +188,17 @@ public class ProjectIdeaSubmissionPanel extends GenericPanel<Idea> {
LambdaModel.of(getModel(), Idea::getProjectType, Idea::setProjectType),
projectTypes,
new LambdaChoiceRenderer<>(ProjectType::getName, ProjectType::getId)
);
) {
@Override
protected IValueMap getAdditionalAttributes(int index, ProjectType choice) {
IValueMap valueMap = super.getAdditionalAttributes(index, choice);
// Have to remove the client side validation for required
// to have this field behave like all the others on the form.
// Can't remove the call to #setRequired(true) as it is needed for server side validation.
valueMap.remove("required");
return valueMap;
}
};
projectTypeChoice.add(
new AjaxFormChoiceComponentUpdatingBehavior() {
@Override