meteor icon indicating copy to clipboard operation
meteor copied to clipboard

input can't have attr name="id", it causes error domutils.js:387

Open crapthings opened this issue 13 years ago • 7 comments

if i put name="id" with input type="text"

// Executes func while ensuring that element has an ID. If element // doesn't have an ID, it is assigned magicId temporarily. // Calls func with a selector of the form "[id='...']" as an argument. var withElementId = function (element, magicId, func) { var didSetId = false; if (! element.id) { element.setAttribute('id', magicId); didSetId = true; } try { var escapedNodeId = element.id.replace(/'/g, "$&"); Uncaught TypeError: Object # has no method 'replace' return func("[id='" + escapedNodeId + "']"); } finally { if (didSetId) element.removeAttribute('id'); } };

crapthings avatar Jan 12 '13 03:01 crapthings

Hi @crapthings,

I am unable to replicate this. I added a text box to an application <input type="text" name="id" />, but did not see any errors.

Can you please post a complete replication? Preferably a URL to a meteor app on github I can clone and run and see the error.

Thanks.

n1mmy avatar Jan 14 '13 21:01 n1mmy

<template name="add-customer">

    <form>
        <table>
            <tbody>
                <tr>
                    <td>客户编号</td>
                    <td>
                        <input type="text" value="{{id}}" disabled>
                        <input type="hidden" name="customerId" value="{{id}}"> // this name just can't be name="id"
                    </td>
                </tr>
                <tr>
                    <td>客户名</td>
                    <td><input type="text" name="name"></td>
                </tr>
                <tr>
                    <td>类型</td>
                    <td>
                        <label><input type="radio" name="type" value="个人">个人</label>
                        <label><input type="radio" name="type" value="企业">企业</label>
                    </td>
                </tr>
                <tr>
                    <td>收货地址</td>
                    <td><textarea name="address" rows="6"></textarea></td>
                </tr>
                <tr>
                    <td>邮政编码</td>
                    <td><input type="text" name="postcode"></td>
                </tr>
                <tr>
                    <td>手机</td>
                    <td><input type="text" name="mobile"></td>
                </tr>
                <tr>
                    <td>电话</td>
                    <td><input type="text" name="tel"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input class="methods-addCustomer" type="button" value="提交">
                    </td>
                </tr>
            </tbody>
        </table>
    </form>

</template>

if i set it to name="id" when i click somewhere in form it causes that error, but i didn't bind any events on form.

Template['add-customer'].events
    'click .methods-addCustomer': (event, template) ->
        customer = $('form').serializeObject()
        Meteor.call 'addCustomer', customer

Template['add-customer'].id = ->
    return Session.get 'customerId'

crapthings avatar Jan 15 '13 03:01 crapthings

Hi @crapthings,

I still can not replicate this from the code you've pasted. Please submit a complete app that demonstrates the problem. From the wiki (https://github.com/meteor/meteor/wiki under Filing Bug Reports):

  • Create a new Meteor app that displays the bug with as little code as possible. Try to delete any code that is unrelated to the precise bug you're reporting.
  • Create a new GitHub repository with a name like meteor-reactivity-bug (or if you're adding a new reproduction recipe to an existing issue, meteor-issue-321) and push your code to it. (Make sure to include the .meteor/packages file!)
  • Reproduce the bug from scratch, starting with a git clone command. Copy and paste the entire command-line input and output, starting with the git clone command, into the issue description of a new GitHub issue. Also describe any web browser interaction you need to do.
  • Specify what version of Meteor ($ meteor --version) and what web browser you used.

n1mmy avatar Feb 06 '13 05:02 n1mmy

@dgreensp looked at this and though we have not replicated, he thinks he knows what's going on. The issue is that if you have a form input with name='foo', it creates an expando attribute called 'foo' on the enclosing <form> tag if any. When this collides with another attribute such as 'id' it's a mess. A possible fix in Meteor is to use node.getAttribute('id') rather than node.id.

@dgreensp is going to look into this, but we still need a working reproduction (as @n1mmy describes) so that we can confirm the problem and the fix.

Until this is fixed, possible workarounds include avoiding name='id', or avoiding putting the input elements inside a <form> tag.

gschmidt avatar Feb 13 '13 01:02 gschmidt

See:

  • http://ejohn.org/blog/deadly-expandos/
  • http://jibbering.com/faq/names/

dgreensp avatar Feb 13 '13 01:02 dgreensp

http://speedy.sh/rZdTu/unknown.zip

mrt and login with username: admin, password: admin then visit http://localhost:3000/settings/users/new

open console

Uncaught TypeError: Object # has no method 'replace'

mrt list --using

coffeescript stylus accounts-password router moment sugar insecure jade-handlebars d3 form2js handlebar-helpers bootstrap-jasny

i've tried to start a new proj and i can't reproduction this error too, don't know what can cause this.

crapthings avatar Feb 13 '13 06:02 crapthings

Fixed on devel; will be in 0.5.7.

Thanks!

dgreensp avatar Feb 15 '13 20:02 dgreensp