use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.
the class DynamicTextAreaFeatureEditor method createInputField.
@Override
protected AbstractTextComponent createInputField() {
textarea = new TextArea<>("value");
textarea.setOutputMarkupId(true);
textarea.add(new AjaxPreventSubmitBehavior());
return textarea;
}
use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project wicket by apache.
the class FormPage method addPreventEnterSubmitForm.
private void addPreventEnterSubmitForm() {
Bean bean = new Bean();
Form<Bean> form = new Form<Bean>("preventEnterForm", new CompoundPropertyModel<>(bean)) {
@Override
protected void onSubmit() {
super.onSubmit();
info("Form successfully submitted!");
}
};
add(form);
form.setOutputMarkupId(true);
addFormComponents(form);
form.add(new AjaxPreventSubmitBehavior());
}
use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.
the class TextAreaFeatureEditor method createInputField.
@Override
protected AbstractTextComponent createInputField() {
TextArea<String> textarea = new TextArea<>("value");
textarea.add(new AjaxPreventSubmitBehavior());
try {
String traitsString = getModelObject().feature.getTraits();
StringFeatureTraits traits = JSONUtil.fromJsonString(StringFeatureTraits.class, traitsString);
textarea.add(new AttributeModifier("rows", traits.getCollapsedRows()));
textarea.add(new AttributeAppender("onfocus", "this.rows=" + traits.getExpandedRows() + ";"));
textarea.add(new AttributeAppender("onblur", "this.rows=" + traits.getCollapsedRows() + ";"));
} catch (IOException e) {
e.printStackTrace();
}
return textarea;
}
use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.
the class InputFieldTextFeatureEditor method createInputField.
@Override
protected AbstractTextComponent createInputField() {
TextField<String> textfield = new TextField<>("value");
textfield.add(new AjaxPreventSubmitBehavior());
return textfield;
}
use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.
the class AnnotationDetailEditorPanel method createForwardAnnotationKeySequenceCapturingForm.
private Component createForwardAnnotationKeySequenceCapturingForm() {
Form<Void> form = new Form<>("forwardForm");
TextField<String> textfield = new TextField<>("forwardAnno");
textfield.setModel(Model.of());
textfield.setOutputMarkupId(true);
// We don't want the form to be submitted when the user pressed ENTER. Instead, we want to
// capture the key event and send it as part of the AJAX request. Note that the
// AjaxPreventSubmitBehavior triggers on "keydown" while our
// AjaxFormComponentUpdatingBehavior has to trigger on "keyup", otherwise the pressed key
// does not end up in the TextField's model.
textfield.add(new AjaxPreventSubmitBehavior());
textfield.add(new AjaxFormComponentUpdatingBehavior("keyup") {
private static final long serialVersionUID = 4554834769861958396L;
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getDynamicExtraParameters().add("return { 'keycode': Wicket.Event.keyCode(attrs.event) };");
}
@Override
protected void onUpdate(AjaxRequestTarget aTarget) {
AnnotatorState state = getModelObject();
// Forward annotation mode only works on span layers
if (!state.getSelection().isSpan()) {
return;
}
// If the user has selected an annotation of a different type or no annotation at
// all, then the forward-annotation key bindings must not be considered.
AnnotationLayer layer = state.getSelectedAnnotationLayer();
if (layer == null || !layer.equals(state.getDefaultAnnotationLayer())) {
return;
}
try {
final Request request = RequestCycle.get().getRequest();
final String jsKeycode = request.getRequestParameters().getParameterValue("keycode").toString("");
if (KEY_ENTER.equals(jsKeycode)) {
CAS cas = getEditorCas();
actionCreateForward(aTarget, cas);
setForwardAnnotationKeySequence(null, "complete annotation (space)");
return;
} else if (KEY_BACKSPACE.equals(jsKeycode)) {
FeatureState featureState = getModelObject().getFeatureStates().get(0);
featureState.value = null;
setForwardAnnotationKeySequence(null, "delete annotation (backspace)");
CAS cas = getEditorCas();
actionCreateForward(aTarget, cas);
} else {
String newTag = (textfield.getModelObject() == null ? "" : textfield.getModelObject().charAt(0)) + getForwardAnnotationKeySequence();
setForwardAnnotationKeySequence(newTag, "cycle tags");
Map<String, String> bindTags = buildKeySequenceToTagMap();
if (!bindTags.isEmpty()) {
FeatureState featureState = getModelObject().getFeatureStates().get(0);
featureState.value = getTagForKeySequence(getForwardAnnotationKeySequence(), bindTags);
}
}
aTarget.add(textfield);
getFeatureEditorListPanel().getFirstFeatureEditor().ifPresent(aTarget::add);
} catch (Exception e) {
handleException(textfield, aTarget, e);
}
}
});
form.add(textfield);
forwardAnnotationTextField = textfield;
return form;
}
Aggregations