Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

issue #19829: parameter filter bugfix

  • Loading branch information...
commit 62dc77a036f8ad10752b15d8c0bc11d5d7a8dc78 1 parent ae31834
@shackbarth shackbarth authored
View
29 lib/enyo-x/source/widgets/parameter.js
@@ -327,13 +327,34 @@ white:true*/
}
},
/**
- @todo Document the setParameterItemValues method.
+ Accepts an array of items to push into the parameter items. Matches item name
+ to component under the assumption that there will be a component by the
+ name of the incoming name (which itself is the name of the model attribute).
+ Fails silently if it cannot find the name.
+
+ @param {Array} items
+ item.name {Array|String} An string *or an array of strings* with the name of
+ the attribute to be updated. In the case of an array, this function will set
+ any component that matches any of the names, and ignore the rest.
+ item.value {Object|String|Number} the payload of the setValue to the ParameterItem.
*/
setParameterItemValues: function (items) {
- var that = this;
+ var that = this,
+ setValueOnMatch = function (name, value) {
+ if (that.$[name]) {
+ that.$[name].setValue(value, {silent: true});
+ }
+ };
+
_.each(items, function (item) {
- if (that.$[item.name]) {
- that.$[item.name].setValue(item.value, {silent: true});
+ if (typeof item.name === 'string') {
+ // string case. set the component by this name
+ setValueOnMatch(item.name, item.value);
+ } else if (typeof item.name === 'object') {
+ // array case. loop through item.name and set any matches
+ _.each(item.name, function (subname) {
+ setValueOnMatch(subname, item.value);
+ });
}
});
}
View
48 node-datasource/test/vows/kinds/parameter.js
@@ -0,0 +1,48 @@
+/*jshint trailing:true, white:true, indent:2, strict:true, curly:true,
+ immed:true, eqeqeq:true, forin:true, latedef:true,
+ newcap:true, noarg:true, undef:true */
+/*global XT:true, XM:true, XV:true, process:true, module:true, require:true */
+
+var XVOWS = XVOWS || {};
+(function () {
+ "use strict";
+
+ var zombieAuth = require("../lib/zombie_auth"),
+ vows = require("vows"),
+ _ = require("underscore"),
+ assert = require("assert");
+
+ /**
+ Test the parameter widget.
+ */
+ vows.describe('The ParameterWidget kind').addBatch({
+ 'When we load up our app': {
+ topic: function () {
+ zombieAuth.loadApp(this.callback);
+ },
+ 'we can create a NumberWidget': {
+ topic: function () {
+ return new XV.ContactListParameters();
+ },
+ 'which can take a string as a filter name and set the item correctly': function (topic) {
+ var valueSet;
+ // XXX probably too much mocking.
+ topic.$.account.setValue = function (value) {
+ valueSet = value.id;
+ };
+ topic.setParameterItemValues([{name: 'account', value: {id: 19}}]);
+ assert.equal(valueSet, 19);
+ },
+ 'which can take an array as a filter name and set the item correctly': function (topic) {
+ var valueSet;
+ // XXX probably too much mocking.
+ topic.$.account.setValue = function (value) {
+ valueSet = value.id;
+ };
+ topic.setParameterItemValues([{name: ['account', 'accountParent'], value: {id: 19}}]);
+ assert.equal(valueSet, 19);
+ }
+ }
+ }
+ }).export(module);
+}());
Please sign in to comment.
Something went wrong with that request. Please try again.