Skip to content

Commit

Permalink
ERJQMobile: Add local array support to AutoComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
swklein committed Apr 15, 2015
1 parent 8d3735b commit 9b939e5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
<wo:if condition = "$hasHiddenValue"> <wo:WOHiddenField value = "$^valueHidden" id = "$hiddenValueId" /> </wo:if>
<script>
$( document ).on( "pageshow", function(event, ui){
<wo:if condition="$hasLocalValues">var data = [<wo:str value = "$localValuesAsString" />];</wo:if>
$('#<wo:str value = "$javaScriptElementID" />').autocomplete({
target: $('#<wo:str value = "$listID" />'),
<wo:if condition = "$jsonDirectActionName">source: '<webobject name = "JsonDirectActionSource" />',</wo:if>
<wo:else>source: '<webobject name = "JsonActionSource" />',</wo:else>
<wo:if condition="$hasLocalValues">source: data,<wo:not condition="$localMatchFromStart">matchFromStart: false, </wo:not></wo:if>
<wo:else>
<wo:if condition = "$jsonDirectActionName">source: '<webobject name = "JsonDirectActionSource" />',</wo:if>
<wo:else>source: '<webobject name = "JsonActionSource" />',</wo:else>
</wo:else>
minLength: <wo:str value = "$minLength" />,
callback: function(e) {
var $a = $(e.currentTarget);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package er.jqm.components.core;

import com.webobjects.appserver.WOContext;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSDictionary;
import com.webobjects.foundation.NSMutableDictionary;

Expand All @@ -12,6 +13,9 @@
* class
* value
*
* localValues
* localMatchFromStart <strong>true</strong> | false
*
* data-corners <strong>true</strong> | false
* data-clear-btn true | <strong>false</strong> - Adds a clear button
* data-clear-btn-text string - Text for the close button. Default: "<strong>clear text</strong>"
Expand Down Expand Up @@ -71,6 +75,47 @@ public String hiddenValueId()
return "h_" + javaScriptElementID();
}

public boolean hasLocalValues()
{
return hasBinding("localValues");
}

public String localValuesAsString()
{
String result = null;
Object obj = _objectValueForBinding("localValues", null, null);
if (obj != null)
{
if (obj instanceof String)
{
result = (String) obj;
}
else if (obj instanceof NSArray)
{
@SuppressWarnings("unchecked")
NSArray<Object> array = (NSArray<Object>) obj;
StringBuffer buf = new StringBuffer();
for (int i = 0; i < array.count(); i++)
{
if (i > 0)
{
buf.append(", ");
}
buf.append("'");
buf.append(array.get(i).toString());
buf.append("'");
}
result = buf.toString();
}
}
return result;
}

public boolean localMatchFromStart()
{
return booleanValueForBinding("localMatchFromStart", true);
}

public String jsonActionClass()
{
return stringValueForBinding("jsonActionClass");
Expand Down

0 comments on commit 9b939e5

Please sign in to comment.