简体   繁体   中英

Ember.js TextField id for label tag with ember router

I have a form that I am building in an Ember.js app that requires the <label> tags be separate from the <input> tags. This has created a problem b/c I cannot seem to bind the for="" attribute of the <label> tag correctly.

I have looked at this Question and the Fiddle in the solution's comments, but it doesn't seem to work with apps that use the Ember.Router architecture

Here is my fiddle exemplifying the issue: http://jsfiddle.net/wmarbut/jKGMW/

I would very muchly prefer not to use any solution that requires me to make actual entries into either my view or controller object for each individual form field.

The quick and dirty of the code can be seen here

<table>
    <tr>
        <th>
            <!-- XXX: How do I bind the "for" attribute correctly? -->
            <label {{bindAttr for="curUser.elementId"}}>Current User</label>
        </th>
        <td>    
            {{view Ember.TextField valueBinding="current_user.first_name" viewName="curUser"}}   
        </td>
    </tr>
</table>

Apparently you need to explicitly access the element at its namespace with view.

This fiddle works: http://jsfiddle.net/wmarbut/jKGMW/5/

updated code would be

<table>
<tr>
    <th>
        <!-- XXX: This now works -->
        <label {{bindAttr for="view.curUser.elementId"}}>Current User</label>
    </th>
    <td>    
        {{view Ember.TextField valueBinding="current_user.first_name" viewName="curUser"}}   
    </td>
</tr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM