Skip to content
Browse files

Add support for labelType in dijit/form/Select, fixes #17746

  • Loading branch information...
1 parent 63fb013 commit fe83f7b78b85b115abe9496e47b50f1489dd3e4e @kriszyp kriszyp committed Feb 19, 2014
Showing with 15 additions and 5 deletions.
  1. +13 −3 form/Select.js
  2. +2 −2 tests/form/test_Select.html
View
16 form/Select.js
@@ -44,7 +44,7 @@ define([
this.inherited(arguments);
this.own(on(this.domNode, "selectstart", function(evt){
- evt.preventDefault();
+ evt.preventDefault();
evt.stopPropagation();
}));
},
@@ -110,6 +110,11 @@ define([
// Whether or not our children have been loaded
_childrenLoaded: false,
+ // labelType: String
+ // Specifies how to interpret the labelAttr in the data store items.
+ // Can be "html" or "text".
+ labelType: "html",
+
_fillContent: function(){
// summary:
// Set the value to be the first, or the selected index
@@ -136,7 +141,9 @@ define([
var click = lang.hitch(this, "_setValueAttr", option);
var item = new MenuItem({
option: option,
- label: option.label || this.emptyLabel,
+ label: (this.labelType === 'text' ? (option.label || '').toString()
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;') :
+ option.label) || this.emptyLabel,
onClick: click,
ownerDocument: this.ownerDocument,
dir: this.dir,
@@ -308,7 +315,10 @@ define([
_setDisplay: function(/*String*/ newDisplay){
// summary:
// sets the display for the given value (or values)
- var lbl = newDisplay || this.emptyLabel;
+
+ var lbl = (this.labelType === 'text' ? (newDisplay || '')
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;') :
+ newDisplay) || this.emptyLabel;
this.containerNode.innerHTML = '<span role="option" class="dijitReset dijitInline ' + this.baseClass.replace(/\s+|$/g, "Label ") + '">' + lbl + '</span>';
},
View
4 tests/form/test_Select.html
@@ -125,7 +125,7 @@
{value: "AK", label: "Alaska"},
{value: "AZ", label: "Arizona"},
{value: "AR", label: "Arkansas"},
- {value: "CA", label: "California"},
+ {value: "CA", label: "Calif<a href='javascript:alert()'>ornia</a>"},
{value: "CO", label: "Colorado"},
{value: "CT", label: "Connecticut"}
];
@@ -885,7 +885,7 @@ <h4 class="testSubtitle">dojo/store based</h4>
</select>
<label for="ds11">Example 3 (Observable)</label>
<select id="ds11" data-dojo-id="ds11" data-dojo-type="dijit/form/Select"
- data-dojo-props='name:"ds11", store:memoryStore3, labelAttr:"label" '>
+ data-dojo-props='name:"ds11", store:memoryStore3, labelType: "text", labelAttr:"label" '>
</select>
<label for="ds11a">Example 3a (Observable, same store as 3)</label>
<select id="ds11a" data-dojo-id="ds11a" data-dojo-type="dijit/form/Select"

0 comments on commit fe83f7b

Please sign in to comment.
Something went wrong with that request. Please try again.