Closed Bug 412529 Opened 17 years ago Closed 16 years ago

removeChild( obj ) from a form still accessible by form[ objID ]

Categories

(Core :: DOM: Core & HTML, defect)

1.8 Branch
x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 307415

People

(Reporter: dpeterson, Unassigned)

Details

Attachments

(3 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

I have a hotlink item that check for the existance of required parameters prior to submitting the form associated with the hotlink.  If the parameter does not exist in the form, a separate form is instantiated to acquire the information in a separate "dialog" window.  That page returns the required date, the data is added dynamically to the form, the form is submitted, and the dynamic entry is removed from the form.  The first time through this works flawlessly, the second time through the check for the form required parameter shows that the parameter is there, but it is not.

$ is used as a shortcut here for document.getElementById()

I'm checking for the form parameter using typeof( $( "MyForm" )[ "ParamName ] ) == undefined.  The first pass this is not defined (expected), a new <input>s are dynamically created inside a dynamically created <div> using document.createElement().

the div is added to the form, the form is submitted and the div is removed:
									oStdRptForm.appendChild( oDiv );
									this.oCaller.RptSubmit();
									oStdRptForm.removeChild( oDiv );

At this point, the innerHTML of oStdRptForm no longer contains any of the dynamic content.  however oStdRptForm[ dynamicObjectID ] returns the input which is no longer part of the form.

full code of the onclick handler is contained in the "Addition Information"

Reproducible: Always

Steps to Reproduce:
1.
2.
3.



		fnRptSubmit = function()
		{
			oStdRptForm = $( "StdRptForm" );
			oStdRptForm.ReportID.value = this.ReportID;

alert( oStdRptForm.innerHTML );

			var iArgNdx;
			var oDiv;
			var oCtrl;
			var iParamNdx = -1;
			var aParams = new Array();
			
			
			for( iArgNdx = 0; iArgNdx < arguments.length; iArgNdx++ )
			{
				try
				{
					iParamNdx += 1;
					aParams[ iParamNdx ] = new Object();
					aParams[ iParamNdx ].id = arguments[ iArgNdx ].split( '=' )[ 0 ];
					aParams[ iParamNdx ].value = arguments[ iArgNdx ].slice( aParams[ iParamNdx ].id.length + 1 );
					
					oCtrl = document.createElement( "INPUT" );
					oCtrl.type = "hidden";
					oCtrl.id = aParams[ iParamNdx ].id;
					oCtrl.name = oCtrl.id;
					oCtrl.value = aParams[ iParamNdx ].value;
					oDiv.appendChild( oCtrl );
				}
				catch( everything )
				{
				}
			}
			
			aReqParams = this.sReqParams.split( ',' );
			for( iNdx = 0; iNdx < aReqParams.length; iNdx++ )
			{
				if( aReqParams[ iNdx ].length != 0 && typeof( oStdRptForm[ aReqParams[ iNdx ] ]) == 'undefined' )
				{
					var oParams = new Object;
					oParams.oCaller = this;
					oParams.aParams = aParams;
					
					oParams.dlgComplete = function()
					{
						switch( this.iRetVal )
						{
							case -2:
									window.location.replace( "#Application.BaseURL#" );
									return;
									
							case 1:
								{
									var iNdx;
									var oDiv

									oStdRptForm = $( "StdRptForm" );
									oDiv = document.createElement( "div" );
									for( iNdx = 0; iNdx < this.aParams.length; iNdx++ )
									{
										oCtrl = document.createElement( "INPUT" );
										oCtrl.type = "hidden";
										oCtrl.id = this.aParams[ iNdx ].id;
										oCtrl.name = oCtrl.id;
										oCtrl.value = this.aParams[ iNdx ].value;
										oDiv.appendChild( oCtrl );
									}
									oStdRptForm.appendChild( oDiv );
									this.oCaller.RptSubmit();
									oStdRptForm.removeChild( oDiv );
								}
								break;									
									
							case -1:
							case 0:
								break;
						}
					}
					SubmitAsDialog( oStdRptForm
										, oParams
										, 'scrollbars:yes;resizable:yes;status:no;width=300px;height=1' 
									); 
					oStdRptForm.removeChild( oDiv );
					return false;
				}
				else
					alert( oStdRptForm[ aReqParams[ iNdx ] ].parentNode.parentNode.innerHTML + "\n else \n " + oStdRptForm.innerHTML );
					
			}
	
			switch( this.TargetID  )
			{
				case 0:
				default:
					oStdRptForm.target = "";
					oStdRptForm.submit();
					break;

				case 1:
					oStdRptForm.target = "_blank";
					oStdRptForm.submit();
					break;
				
				case 2: 
					var oParams = new Object;
					oParams.dlgComplete = function()
					{
						switch( this.iRetVal )
						{
							case -2:
									window.location.replace( "#Application.BaseURL#" );
									return;
									
							case -1:
							case 0:
							case 1:
								break;
						}
					}
					SubmitAsDialog( oStdRptForm
												, oParams
												, 'scrollbars:yes;resizable:yes;status:no;' 
											); 
					
					break;
			}		
			return false;
		}
forgot to mention.  after your form has had the child removed, and you get to the abandoned child via form[ "childid" ], the object returned doesn't have a parent (as you would expect if it was abandoned, but the former parent still appears to know about it.)
Component: Form Manager → DOM
Product: Firefox → Core
QA Contact: form.manager → general
Version: unspecified → 1.8 Branch
Sorry, may not be obvious.  The form in this case isn't actually submitted normally.  Rather, I have a routine that pulls all the form parameters, builds a CGI string, appends it to the Action and calls Open( action + cgi, obj, flags ) then returns.  So the form's submit is never actually called. 

I'm attaching some test code that is short and to the point.
Attached file Reproducing error
I've the same issue.
I ran into this issue in v. 2.0.0.14 and v. 3rc1.

In my case I was looping through the form elements using document.forms[0]['elementname'] where elementname included an incremented numeric field.  I found that looping through the form like document.forms[0][0] will properly skip form elements that have been removed from the document.
When a form control is referenced as a property of a form, directly off the form, as in document.forms[0].test, and the form control named "test" is removed, the form control can still be referenced as a property of the form.

However, if the form control is not referenced as a property of a form, and then it is removed, it will not be possible to obtain a reference to the form control as a property.
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → DUPLICATE
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: