Opened 7 years ago

Closed 7 years ago

#16028 closed defect (fixed)

[regression] Unable to set dojoxform.TriStateCheckbox states

Reported by: Bill Reed Owned by: cjolif
Priority: undecided Milestone: 1.8.2
Component: DojoX Form Version: 1.8.0
Keywords: Cc: bill, Douglas Hays, siqi.zhong@…, mikeb
Blocked By: Blocking:

Description

I am unable to set the states attribute of a dojox.form.TriStateCheckbox from a string in HTML Markup. If I have the following HTML

	<input data-dojo-type="dojox.form.TriStateCheckBox" states="true, mixed, false"  ></input>

The TriStateCheckbox does not unchecked when I iterate through the states I see a true state (a check) a mixed state (the square colored in) but for the false state I see a check in the check box. If I look at the documents HTML when in the false state I see

	<input data-dojo-type="dojox.form.TriStateCheckBox" checked="false" ></input>

Looking at the code for dojox.form.TriStateCheckBox I see that for dojo 1.8 when the object is instantiate the code now sets the property state to:

		states: "",

		// states: Array
		//		States of TriStateCheckBox.
		//		The value of This.checked should be one of these three states:
		//		[false, true, "mixed"]
		states: [false, true, "mixed"],

compared to dojo 1.7:

/**
		 * States cycle of a TriStateCheckBox. By default it's [false, "mixed", true] which means the state cycles from
		 * 'unchecked' -> 'indeterminate' -> 'checked'.
		 * Note: The value of the 'checked' property of a TriStateCheckBox should be one of these states.
		 * For example, if the 'states' property of a TriStateCheckBox is [false, true], then setting 'checked'
		 * property to 'midex' is invalid.
		 * @type Array|String
		 * @default [false, "mixed", true]
		 */
		states: "",

This change seems to be the root cause of the problem, when the object is constructed and dojo.parser.constructor at line 340 uses the prop objects property type to parse the attribute

default:
	var pVal = proto[name];
	params[name] =
	    (pVal && "length" in pVal) ? (value ? value.split(/\s*,\s*/) : []) :	// array
	    (pVal instanceof Date) ? (value == "" ? new Date("") :	// the NaN of dates
	    value == "now" ? new Date() :	// current date
	    dates.fromISOString(value)) : 
              (pVal instanceof _Url) ? (dojo.baseUrl + value) :
			djson.fromJson(value);
	}

So in the case of the states attribute of TriStateCheckbox the states property is an array so the string as treated as an array. So when TriStateCheckbox._setStatesAttr is called what is passed in is an array ['false','mixed','true'] So the parsing and mapping of the states string never happends.

_setStatesAttr: function(/*Array|String*/ states){
			debugger;
			if(lang.isArray(states)){
				this._set("states", states);
			}else if(lang.isString(states)){
				var map = {
					"true": true,
					"false": false,
					"mixed": "mixed"
				};
				states = states.split(/\s*,\s*/);
				for(var i = 0; i < states.length; i++){
					states[i] = map[states[i]] !== undefined ? map[states[i]] : false;
				}
				this._set("states", states);
			}
		},

If I comment out the initialization of states at line 35 so that states is a "" as it was in dojo 1.7 the code works. I am also concerned about the initialization of stateValues and _stateLabels as they could have similar issues

I will attach a test case the demonstrates the issue and a patch

Attachments (2)

TriStateCheckBox.js.patch (1.8 KB) - added by Bill Reed 7 years ago.
Patch file
test_TriStateCheckbox.html (2.0 KB) - added by Bill Reed 7 years ago.
test case

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by Bill Reed

Attachment: TriStateCheckBox.js.patch added

Patch file

Changed 7 years ago by Bill Reed

Attachment: test_TriStateCheckbox.html added

test case

comment:1 Changed 7 years ago by Adam Peller

Cc: bill Douglas Hays siqi.zhong@… added
Owner: changed from dante to cjolif
Status: newassigned

comment:2 Changed 7 years ago by Adam Peller

Milestone: tbd1.8.2
Summary: Unable to set dojoxform.TriStateCheckbox states[regression] Unable to set dojoxform.TriStateCheckbox states

comment:3 Changed 7 years ago by cjolif

if that is a regression did you identify which commit broke it? That would help reviewing this in context?

comment:4 in reply to:  3 Changed 7 years ago by siqi

Replying to cjolif:

if that is a regression did you identify which commit broke it? That would help reviewing this in context?

I think Bill is right... line 35 should be commented... The issue was introduced in the commit [28875]... Compare it with revision [28677], you can find that it used to look like:

		states: "",
		/*=====
		// states: Array
		//		States of TriStateCheckBox.
		//		The value of This.checked should be one of these three states.
		states: [false, true, "mixed"],
		=====*/

Thanks

Last edited 7 years ago by bill (previous) (diff)

comment:5 Changed 7 years ago by cjolif

Cc: mikeb added

comment:6 Changed 7 years ago by cjolif

In [29813]:

refs #16028. Fix TriStateCheckBox? regression in trunk.

comment:7 Changed 7 years ago by cjolif

Resolution: fixed
Status: assignedclosed

In [29822]:

fixes #16028. Backport fix to 1.8.

Note: See TracTickets for help on using tickets.