Create button should not be visible until user has selected project type

Previously a user could click on the create button before they had chosen a
grading template project type from the Project type dropdown.
This would result in a runtime exception, and possibly in an unhappy user.

To protect the user from "jumping the gun", the Create button will only become visible
after the user has selected a Project type from the dropdown menu.
This commit is contained in:
Nico Athanassiadis 2024-11-20 10:34:40 +01:00
parent 883ccfc26d
commit edd6e9214d
2 changed files with 10 additions and 2 deletions
view/src/main/java/se/su/dsv/scipro/admin/pages/grading

@ -17,7 +17,7 @@
<div wicket:id="grading_template_component_panel"></div> <div wicket:id="grading_template_component_panel"></div>
<div class="position-sticky bottom-0 bg-white p-3 border line-length-limit"> <div wicket:id="button_container" class="position-sticky bottom-0 bg-white p-3 border line-length-limit">
<button type="submit" class="btn btn-primary">Create</button> <button type="submit" class="btn btn-primary">Create</button>
</div> </div>
</form> </form>

@ -3,6 +3,7 @@ package se.su.dsv.scipro.admin.pages.grading;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import org.apache.wicket.RestartResponseException; import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.LambdaChoiceRenderer; import org.apache.wicket.markup.html.form.LambdaChoiceRenderer;
import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.markup.html.panel.FeedbackPanel;
@ -29,6 +30,7 @@ public class AdminGradingTemplateCreationPage extends AbstractAdminProjectPage i
private final IModel<ProjectType> projectTypeModel; private final IModel<ProjectType> projectTypeModel;
private EditingGradingTemplate editingGradingTemplateModel; private EditingGradingTemplate editingGradingTemplateModel;
private final WebMarkupContainer buttonContainer;
public AdminGradingTemplateCreationPage() { public AdminGradingTemplateCreationPage() {
projectTypeModel = new DetachableServiceModel<>(projectTypeService); projectTypeModel = new DetachableServiceModel<>(projectTypeService);
@ -57,6 +59,11 @@ public class AdminGradingTemplateCreationPage extends AbstractAdminProjectPage i
form.setOutputMarkupId(true); form.setOutputMarkupId(true);
add(form); add(form);
buttonContainer = new WebMarkupContainer("button_container");
buttonContainer.setOutputMarkupPlaceholderTag(true);
buttonContainer.setVisible(false);
form.add(buttonContainer);
form.add(new AjaxDropDownChoice<>( form.add(new AjaxDropDownChoice<>(
"project_type", "project_type",
projectTypeModel, projectTypeModel,
@ -64,7 +71,8 @@ public class AdminGradingTemplateCreationPage extends AbstractAdminProjectPage i
new LambdaChoiceRenderer<>(ProjectType::getName, ProjectType::getId)) { new LambdaChoiceRenderer<>(ProjectType::getName, ProjectType::getId)) {
@Override @Override
public void onNewSelection(AjaxRequestTarget target, ProjectType objectSelected) { public void onNewSelection(AjaxRequestTarget target, ProjectType objectSelected) {
target.add(form); buttonContainer.setVisible(true);
target.add(form, buttonContainer);
} }
}); });