Fix for ticket# 2528732 #48

Closed
wants to merge 3 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+38 −7
Split
@@ -750,8 +750,12 @@
}
if (setter) {
retVal = setter.call(host, newVal, name);
-
- if (retVal === INVALID_VALUE) {
+
+ if (retVal === INVALID_VALUE && initializing) {
+ Y.log('Attribute: ' + attrName + ', setter returned Attribute.INVALID_VALUE for value:' + newVal
+ + ', initializing to default value', 'warn', 'attribute');
+ newVal = state.get(attrName, DEF_VALUE);
+ } else if (retVal === INVALID_VALUE) {
Y.log('Attribute: ' + attrName + ', setter returned Attribute.INVALID_VALUE for value:' + newVal, 'warn', 'attribute');
allowSet = false;
} else if (retVal !== undefined){
@@ -213,8 +213,8 @@
return this.get("D") + this.get("E");
}
},
-
- complex: {
+
+ complex: {
value: {
X : {
A: 1
@@ -697,7 +697,35 @@
Y.Assert.areEqual("MyDEVal", h.get("DE"));
},
-
+ testDefaultSet : function() {
+ function TestClass(config) {
+ TestClass.superclass.constructor.apply(this, arguments);
+ };
+
+ TestClass.NAME = "testClass";
+
+ TestClass.ATTRS = {
+ FOO : {
+ value: "Default FOO",
+ setter: function ( v ) {
+ if ( v !== 'A' && v !== 'B' ) {
+ return Y.Attribute.INVALID_VALUE;
+ }
+ return v;
+ }//end of setter.
+ }
+ };
+
+ Y.extend(TestClass, Y.Base);
+ var m = new TestClass({'FOO':'BAR'});
+ Y.Assert.areNotEqual(undefined, m.get("FOO"));
+ Y.Assert.areEqual("Default FOO", m.get("FOO"));
+ m.set('FOO','ATT');//set a invalid value
+ Y.Assert.areEqual("Default FOO", m.get("FOO"));
+ m.set('FOO','A');//set a invalid value
+ Y.Assert.areEqual("A", m.get("FOO"));
+ Y.log("val of FOO:" + m.get('FOO'));
+ },
testSet : function() {
var h = this.createHost();
@@ -717,7 +745,6 @@
Y.Assert.areEqual("MyNewDEVal", h.get("DE"));
},
-
testWriteOncePostInit : function() {
var h = this.createHost();
@@ -1792,4 +1819,4 @@
<body class="yui3-skin-sam">
<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
</body>
-</html>
+</html>
@ericf

ericf Dec 20, 2012

Owner

Add newline.