Browse files

KeyValue: do not write in the original options object and adding oper…

…ators and operatorLabels options to KeyOpValue
  • Loading branch information...
1 parent 93440a5 commit d08310bbfdc4199c249f0b95e45dae44800bb9c3 @neyric neyric committed Feb 14, 2010
Showing with 52 additions and 12 deletions.
  1. +28 −0 examples/keyopvalue_field.html
  2. +15 −7 js/fields/KeyOpValueField-beta.js
  3. +9 −5 js/fields/KeyValueField-beta.js
View
28 examples/keyopvalue_field.html
@@ -95,5 +95,33 @@
</div>
+
+<!-- Example 3 -->
+<div class='exampleDiv'>
+ <p class="title">Changing the operators and setting labels for operators</p>
+ <p>Two more options are available for this field: "operators" and "operatorLabels"</p>
+ <div class='demoContainer' id='container3'></div>
+ <div class='codeContainer'>
+ <textarea name="code" class="JScript">
+ var field = new inputEx.KeyOpValueField({
+ parentEl: 'container3',
+ availableFields: [
+ {type: 'string', name: 'lastname', label: 'Lastname' },
+ {type: 'string', name: 'firstname', label: 'Firstname' },
+ {type: 'select', name: 'gender', label: 'Gender', selectValues: ["Mr", "Mme","Mlle"] }
+ ],
+
+ operators: ["=","!="],
+ operatorLabels: ["equals", "different"]
+ });
+
+ var button = inputEx.cn('button', null, null, 'getValue()');
+ YAHOO.util.Dom.get('container3').appendChild(button);
+ YAHOO.util.Event.addListener(button, 'click', function() { alert( YAHOO.lang.JSON.stringify(field.getValue())); });
+
+ </textarea>
+ </div>
+</div>
+
</body>
</html>
View
22 js/fields/KeyOpValueField-beta.js
@@ -16,14 +16,22 @@ YAHOO.lang.extend( inputEx.KeyOpValueField, inputEx.KeyValueField, {
setOptions: function(options) {
var selectFieldConfig = this.generateSelectConfig(options.availableFields);
-
- options.fields = [
- selectFieldConfig,
- {type: 'select', selectValues: ["=", ">", "<", ">=", "<=", "!=", "LIKE", "NOT LIKE", "IS NULL", "IS NOT NULL"] },
- this.nameIndex[options.availableFields[0].name]
- ];
- inputEx.KeyValueField.superclass.setOptions.call(this, options);
+ var newOptions = {
+ fields: [
+ selectFieldConfig,
+ {type: 'select', selectValues: options.operators || ["=", ">", "<", ">=", "<=", "!=", "LIKE", "NOT LIKE", "IS NULL", "IS NOT NULL"] },
+ this.nameIndex[options.availableFields[0].name]
+ ]
+ };
+
+ if(options.operatorLabels) {
+ newOptions.fields[1].selectOptions = options.operatorLabels;
+ }
+
+ YAHOO.lang.augmentObject(newOptions, options);
+
+ inputEx.KeyValueField.superclass.setOptions.call(this, newOptions);
}
});
View
14 js/fields/KeyValueField-beta.js
@@ -53,12 +53,16 @@ YAHOO.lang.extend( inputEx.KeyValueField, inputEx.CombineField, {
var selectFieldConfig = this.generateSelectConfig(options.availableFields);
- options.fields = [
- selectFieldConfig,
- this.nameIndex[options.availableFields[0].name]
- ];
+ var newOptions = {
+ fields: [
+ selectFieldConfig,
+ this.nameIndex[options.availableFields[0].name]
+ ]
+ };
- inputEx.KeyValueField.superclass.setOptions.call(this, options);
+ YAHOO.lang.augmentObject(newOptions, options);
+
+ inputEx.KeyValueField.superclass.setOptions.call(this, newOptions);
},
/**

0 comments on commit d08310b

Please sign in to comment.