Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Keep hidden field value up to date with changes

  • Loading branch information...
commit cf1d129b9189352a9fe500f3a1a8c724d4dd45d1 1 parent 1dc179a
@hlship authored
Showing with 26 additions and 16 deletions.
  1. +26 −16 tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx.js
View
42 tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx.js
@@ -357,12 +357,6 @@ Tapx.extendInitializer(function() {
var availableSelect = mainDiv.down(".tx-available > select");
var selectedSelect = mainDiv.down(".tx-selected > select");
- var optionToValue = {};
- // First array is the list of selected values (for values defined by the
- // model) Second array is the list of selected labels (for values
- // added on the client)
- var hiddenFieldValue = [ [], [] ];
-
(spec.model || []).each(function(row) {
var valueId = row[0];
@@ -371,27 +365,43 @@ Tapx.extendInitializer(function() {
var option = new Element("option").update(row[1]);
- optionToValue[option] = {
- clientValue : row[0]
+ option.txValue = {
+ clientValue : valueId
};
- if (selected) {
- hiddenFieldValue[0].push(row[0]);
- }
-
divToUpdate.insert(option);
});
- hidden.value = hiddenFieldValue.toJSON();
+ function rebuildHiddenFieldValue() {
+ // First array is the list of selected values (for values defined by
+ // the model) Second array is the list of selected labels (for
+ // values added on the client)
+
+ var hiddenFieldValue = [ [], [] ];
+
+ $A(selectedSelect.options).each(function(option) {
+ var value = option.txValue;
+
+ if (value.clientValue) {
+ hiddenFieldValue[0].push(value.clientValue);
+ } else {
+ hiddenFieldValue[1].push(value.label);
+ }
+ });
+
+ hidden.value = hiddenFieldValue.toJSON();
+ }
+
+ rebuildHiddenFieldValue();
setupButton(availableSelect, mainDiv.down(".tx-select"), function() {
- Tapestry.debug("select clicked");
transferOptions(availableSelect, selectedSelect);
+ rebuildHiddenFieldValue();
+
});
setupButton(selectedSelect, mainDiv.down(".tx-deselect"), function() {
- Tapestry.debug("deselect clicked");
transferOptions(selectedSelect, availableSelect);
-
+ rebuildHiddenFieldValue();
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.