form2js icon indicating copy to clipboard operation
form2js copied to clipboard

js2form node walking not working

Open lookfirst opened this issue 14 years ago • 3 comments

Hi Max,

I've got a structure that looks like the html below. The issue is that the form isn't getting populated correctly. The phone field shows up fine, but none of the address fields show up. Stepping through the code, it appears as though js2form.getFields() doesn't walk the tree correctly. I see it find the 'addressInfo' id, but nothing within the table. Any ideas?

<table>
<tbody>
<tr>
    <th>Phone</th>
    <td><input type="text" id="phone" name="phone" /></td>
</tr>
<tr>
    <th>Address</th>
    <td>
        <table id="addressInfo" class="condensed-table">
            <tr>
                <th>Street 1</th>
                <td><input type="text" id="address.street1" name="address.street1" /></td>
            </tr>
            <tr>
                <th>Street 2</th>
                <td><input type="text" id="address.street2" name="address.street2" /></td>
            </tr>
            <tr>
                <th>City</th>
                <td><input type="text" id="address.city" name="address.city" /></td>
            </tr>
            <tr>
                <th>State</th>
                <td><input type="text" id="address.state" name="address.state" /></td>
            </tr>
            <tr>
                <th>Zip</th>
                <td><input type="text" id="address.zip" name="address.zip" /></td>
            </tr>
            <tr>
                <th>Country</th>
                <td><input type="text" id="address.country" name="address.country" /></td>
            </tr>
        </table>
    </td>
</tr>
</tbody>
</table>

lookfirst avatar Nov 30 '11 05:11 lookfirst

Ok, further testing shows that it only fails when j2form is used with useIdIfEmptyName = true.

js2form(document.getElementById('testForm'), data, '.', null, true);

lookfirst avatar Nov 30 '11 06:11 lookfirst

I've updated the example to show the broken issue...

https://github.com/lookfirst/form2js/commit/bc97b68a844772b3ec7cce976f3aa8adb56680e8

lookfirst avatar Nov 30 '11 06:11 lookfirst

Sorry, field should have been true:

https://github.com/lookfirst/form2js/commit/da898773336a4722e982198a54bb4474e309e7e1

lookfirst avatar Nov 30 '11 06:11 lookfirst