Bug Tracker

Modify

Ticket #4417 (closed bug: duplicate)

Opened 5 years ago

Last modified 2 years ago

problem with attribute name when clone in IE7

Reported by: boneazul Owned by:
Priority: low Milestone: 1.5
Component: manipulation Version: 1.3.2
Keywords: clone attribute Cc:
Blocking: Blocked by:

Description

there is a problem in IE7 when clone elements, after change name elements .

I want to clone a tr element ,but clone in FF and IE7 show diferents results look the example

Attachments

jquery_close.html Download (412 bytes) - added by boneazul 5 years ago.
clone_function_upgraded.js Download (2.6 KB) - added by boneazul 5 years ago.
new clone method
jquery.js Download (118.8 KB) - added by boneazul 5 years ago.
jquery1.3.2 with method clone modified
teste.HTML Download (948 bytes) - added by boneazul 5 years ago.
test case .html
test_v2.HTML Download (4.1 KB) - added by jerone 5 years ago.
test v2

Change History

Changed 5 years ago by boneazul

comment:1 Changed 5 years ago by boneazul

alert test in FF3 shows me <td><input id="test" name="a[]"></td>

when in IE7 shows me <td><input id=test name=a></td>

is this a bug??

comment:2 Changed 5 years ago by jerone

IE7 is correct here; as W3C says

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

comment:3 Changed 5 years ago by boneazul

the problem is not in the name with especial caracters.

Change the concat "[]" to another letter like "b" in this script the same problem is detected follow this code

<html>

<head>

<title></title> <meta content=""> <style></style>

<script src=" http://code.jquery.com/jquery-latest.js"></script> <script>

$(function(){

this point we concat the name white letter b (W3C says that is not wrong) ok? $("#test").attr('name',$("#test").attr('name')+"b"); Now we clone the line var obj_tr_clone=$("#line").clone(true); Show html clone alert(obj_tr_clone.html());

});

</script>

</head> <body>

<table>

<tr id="line">

<td><input id="test" name="a"></td>

</tr>

</table> </body>

</html>

In fact what happened .

1 - We change the name "a" to "ab" 2- Clone the line 3 - Alert the html clone

FF is ok because he shows me the new name in alert -> "ab" "<td><input id="test" name="ab"></td>"

but in IE7 he shows me the old name in alert -> "a" and don't change the name (its wrong as i can see) why he don't change the name??? "<td><input id=test name=a></td>"

who is wrong ?? the method clone()?? the method html()?? or IE7??

sorry about my poor english..

comment:4 Changed 5 years ago by boneazul

IE copies events bound via attachEvent when

using cloneNode. Calling detachEvent on the clone will also remove the events from the orignal In order to get around this, we use innerHTML.

Unfortunately, this means some modifications to attributes in IE that are actually only stored as properties will not be copied (such as the the name attribute on an input).

i found it in script jquery.js the problem looks like in IE7 Unfortunately i'm right??

comment:5 Changed 5 years ago by dmethvin

Yes, this looks like it has also been reported in a slightly different situation in ticket #4422. It seems like IE is stripping off the quotes and that is causing some bizarre problems.

comment:6 Changed 5 years ago by boneazul

i found the problem....

in fact jquery use outerHTML to clone the html element and IE7 respond with the first html rended(why??i don't now)

example if you render first

<input type="text" name="a" id="aa"> and change any attribute via javascript after dom loaded like (name,id) or any framework javascript will not be correct avaiable in outerHTML method

html always will be cloned as <input type="text" name="a" id="aa"> same as any attribute be modified

however a way to fix it, is upgrade method clone in jquery to find all childs inside outerHTML and replace this attibutes like (name,id,size,...) to real values .there is possible and it is easy to do.I will write a pseudo code then workaround this ..and suggest to core jquery to fix this problem.

and pray to IE fix it.. :)

comment:7 Changed 5 years ago by jerone

Maybe it's an idea to temporary store these attributes before cloning and attach them after.

comment:8 Changed 5 years ago by boneazul

ok i'm here again... i wrote a little code upgrading method clone in jquery core to fix the problem with name in IE6 + that not suport jQuery.support.noCloneEvent

and i would like ask you to test the code..

works fine in the diferents test cases..

if you want to update or upgrade the code to some more simple or generic thats ok...

just give me the credits.. :)

@Jonatan de Sá Lemes - Brazil

i guess then i solvet it in 14 lines to aggregate in core function ...

the codes and tests cases is attached

Changed 5 years ago by boneazul

new clone method

Changed 5 years ago by boneazul

jquery1.3.2 with method clone modified

Changed 5 years ago by boneazul

test case .html

comment:9 Changed 5 years ago by jerone

I did some testing of your script and it seems it works great.

The only problem with it was that it worked with browser identification, which is a big no in jQuery. I've come up with a support solution that checks if the browser has support for special characters in attributes (name).

I've updated your test file with the new function.

Hope it gets approved.

Changed 5 years ago by jerone

test v2

comment:10 Changed 5 years ago by boneazul

now it's great.Thank you for you helping. i did some another tests and the problem doens't happen with another attributes like id,size,etc just with name attribute..very strange..: ) .it's ok now.

this change will be applied in jquery clone method v1.3.3 ???

i hope so.if not thank you.help'm a lot.

comment:11 Changed 4 years ago by vishvananda

this is still causing issues with trailing slashes in action parameters of forms. Is there a decent workaround? For now I'm adding the action after I clone the form

comment:12 Changed 4 years ago by dmethvin

  • Component changed from unfiled to manipulation

comment:13 Changed 4 years ago by grjasewe

It is a problem for struts2-jquery-grid. See  http://www.trirand.com/blog/?page_id=393/help/multiple-search-multiple-criteria-same-field/#p19979. Any more news on a resoultion for this bug?

comment:14 Changed 4 years ago by SlexAxton

  • Keywords clone attribute added
  • Priority changed from major to low
  • Status changed from new to open
  • Milestone changed from 1.4 to 1.5

comment:15 Changed 3 years ago by snover

  • Status changed from open to closed
  • Resolution set to duplicate

This ticket is confusing. Closing as a duplicate of the much clearer #6236.

comment:16 Changed 3 years ago by snover

Duplicate of #6236.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.