Skip to content

Commit

Permalink
rework AjaxObserveField to listen on input rather than on keyUp
Browse files Browse the repository at this point in the history
  • Loading branch information
must21de authored and markusstoll committed Jul 9, 2019
1 parent 92c9f0b commit 4dcb9ce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Frameworks/Ajax/Ajax/Components/AjaxObserveField.api
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<binding name="onSuccess"/>
<binding name="onFailure"/>
<binding name="onException"/>
<binding name="actOnKeyUp"/>
<binding name="actOnInput"/>
</wo>
</wodefinitions>
10 changes: 5 additions & 5 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxObserveField.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
* @binding onCreate Takes a JavaScript function which is called after the form has been serialized,
* but before the Ajax request is sent to the server. Useful e.g. if you want to disable the
* form while the ajax request is running.
* @binding actOnKeyUp When true, keyup events in text input fields lead to an immediate action
* @binding actOnInput When true, input events in text input fields lead to an immediate action
*/
public class AjaxObserveField extends AjaxDynamicElement {
public AjaxObserveField(String name, NSDictionary<String, WOAssociation> associations, WOElement children) {
Expand Down Expand Up @@ -103,7 +103,7 @@ public void appendToResponse(WOResponse response, WOContext context) {
String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
NSMutableDictionary<String, String> options = createAjaxOptions(component);
boolean fullSubmit = booleanValueForBinding("fullSubmit", false, component);
boolean actOnKeyUp = booleanValueForBinding("actOnKeyUp", false, component);
boolean actOnInput = booleanValueForBinding("actOnInput", false, component);
boolean observeFieldDescendents;
if (observeFieldID != null) {
observeFieldDescendents = false;
Expand All @@ -127,14 +127,14 @@ public void appendToResponse(WOResponse response, WOContext context) {
response.appendContentString("</" + elementName + ">");
}
AjaxUtils.appendScriptHeader(response);
AjaxObserveField.appendToResponse(response, context, this, observeFieldID, observeFieldDescendents, updateContainerID, fullSubmit, options, actOnKeyUp);
AjaxObserveField.appendToResponse(response, context, this, observeFieldID, observeFieldDescendents, updateContainerID, fullSubmit, options, actOnInput);
AjaxUtils.appendScriptFooter(response);
}

public static void appendToResponse(WOResponse response, WOContext context, AjaxDynamicElement element, String observeFieldID, boolean observeDescendentFields, String updateContainerID, boolean fullSubmit, NSMutableDictionary options) {
appendToResponse(response, context, element, observeFieldID, observeDescendentFields, updateContainerID, fullSubmit, options, false);
}
public static void appendToResponse(WOResponse response, WOContext context, AjaxDynamicElement element, String observeFieldID, boolean observeDescendentFields, String updateContainerID, boolean fullSubmit, NSMutableDictionary options, boolean actOnKeyUp) {
public static void appendToResponse(WOResponse response, WOContext context, AjaxDynamicElement element, String observeFieldID, boolean observeDescendentFields, String updateContainerID, boolean fullSubmit, NSMutableDictionary options, boolean actOnInput) {
WOComponent component = context.component();
String submitButtonName = nameInContext(context, component, element);
NSMutableDictionary<String, String> observerOptions = new NSMutableDictionary<>();
Expand Down Expand Up @@ -163,7 +163,7 @@ public static void appendToResponse(WOResponse response, WOContext context, Ajax
response.appendContentString(observeDelay);
response.appendContentString(", ");
AjaxOptions.appendToResponse(observerOptions, response, context);
response.appendContentString(", " + actOnKeyUp +");");
response.appendContentString(", " + actOnInput +");");
}

public static String nameInContext(WOContext context, WOComponent component, AjaxDynamicElement element) {
Expand Down
4 changes: 2 additions & 2 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUpdateContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ public void appendToResponse(WOResponse response, WOContext context) {

if (observeFieldID != null) {
boolean fullSubmit = booleanValueForBinding("fullSubmit", false, component);
boolean actOnKeyUp = booleanValueForBinding("actOnKeyUp", false, component);
AjaxObserveField.appendToResponse(response, context, this, observeFieldID, false, id, fullSubmit, createObserveFieldOptions(component), actOnKeyUp);
boolean actOnInput = booleanValueForBinding("actOnInput", false, component);
AjaxObserveField.appendToResponse(response, context, this, observeFieldID, false, id, fullSubmit, createObserveFieldOptions(component), actOnInput);
}

response.appendContentString("AUC.register('" + id + "'");
Expand Down
16 changes: 8 additions & 8 deletions Frameworks/Ajax/Ajax/WebServerResources/wonder.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,15 @@ var AjaxSubmitButton = {
new Ajax.Request(finalUrl, finalOptions);
},

observeDescendentFields: function(updateContainerID, containerID, observeFieldFrequency, partial, observeDelay, options, actOnKeyUp) {
observeDescendentFields: function(updateContainerID, containerID, observeFieldFrequency, partial, observeDelay, options, actOnInput) {
$(containerID).descendants().find(function(element) {
if (element.type != 'hidden' && ['input', 'select', 'textarea'].include(element.tagName.toLowerCase())) {
AjaxSubmitButton.observeField(updateContainerID, element, observeFieldFrequency, partial, observeDelay, options, actOnKeyUp);
AjaxSubmitButton.observeField(updateContainerID, element, observeFieldFrequency, partial, observeDelay, options, actOnInput);
}
});
},

observeField: function(updateContainerID, formFieldID, observeFieldFrequency, partial, observeDelay, options, actOnKeyUp) {
observeField: function(updateContainerID, formFieldID, observeFieldFrequency, partial, observeDelay, options, actOnInput) {
var submitFunction;
if (partial) {
// We need to cheat and make the WOForm that contains the form action appear to have been
Expand Down Expand Up @@ -531,7 +531,7 @@ var AjaxSubmitButton = {
new Form.Element.RadioButtonObserver($(formFieldID), submitFunction);
}
else {
new Form.Element.ExtendedEventObserver($(formFieldID), submitFunction, actOnKeyUp);
new Form.Element.ExtendedEventObserver($(formFieldID), submitFunction, actOnInput);
}
}
else {
Expand Down Expand Up @@ -1000,8 +1000,8 @@ Form.Element.RadioButtonObserver = Class.create(Form.Element.EventObserver, {
});

Form.Element.ExtendedEventObserver = Class.create(Form.Element.EventObserver, {
initialize: function($super, element, callback, actOnKeyUp) {
this.actOnKeyUp = actOnKeyUp;
initialize: function($super, element, callback, actOnInput) {
this.actOnInput = actOnInput;
$super(element, callback);
},

Expand All @@ -1015,9 +1015,9 @@ Form.Element.ExtendedEventObserver = Class.create(Form.Element.EventObserver, {
case 'text':
case 'number':
Event.observe(element, 'change', this.onElementEvent.bind(this));
if (this.actOnKeyUp)
if (this.actOnInput)
{
Event.observe(element, 'keyup', this.onElementEvent.bind(this));
Event.observe(element, 'input', this.onElementEvent.bind(this));
Event.observe(element, 'blur', this.onElementEvent.bind(this));
}
break;
Expand Down

0 comments on commit 4dcb9ce

Please sign in to comment.