0

I'm ng-repeating over a collection of items, and each item I want to have its own form and its own submit button, which will send that form info to the submit function. I needed to know which item is being submitted, so I figured I'd create one form per item and that would indicate which one is being submitted. Currently, it's in an li ng-repeat like so:

<input ng-model="query" type="text" placeholder="Filter by" autofocus>
<ul class="gNow">
    <li ng-repeat="item in selRole.selectRoles | multifilter:query">
        <form name="selRoleForm-{{item.rowId}}" ng-submit="selRole.selectRole(selRoleForm-{{item.rowId}})" novalidate>
            <div class="card">
                <p>Card Name: {{item.cardName}}</p>
                <p>.. other form elements here ..</p>
                <p><button type="submit">Select</button></p>
            </div>
        </form>
    </li>
</ul>

I'm getting the following error:

[$parse:syntax] Syntax Error: Token '{' invalid key at column 33 of the expression [selRole.selectRole(selRoleForm-{{item.rowId}})] starting at [{item.rowId}})].

What am I doing incorrectly - or is there a better way to approach this problem?

This SO post is the closest that I could find to my problem, but still, I'm not sure I understand how to adjust to my specific needs.

1
  • Do not include solution to question please (post a separate answer instead). Commented Dec 28, 2024 at 21:13

3 Answers 3

1

Just store the form name in your ng-repeated array:

<input ng-model="query" type="text" placeholder="Filter by" autofocus>
<ul class="gNow">
    <li ng-repeat="item in selRole.selectRoles | multifilter:query">
        <form name="{{item.formName}}" ng-submit="selRole.selectRole(item.formName)" novalidate>
        ...
Sign up to request clarification or add additional context in comments.

1 Comment

This fixed the syntax error, which pointed me in the right direction. This allowed me to see the real problem, which was not passing the correct object in the ng-submit function. Added update to question with solution.
1

Use ngForm :

<div class="form-group" ng-repeat="item in selRole.selectRoles | multifilter:query">
  <ng-form name="userFieldForm">
    <label></label>
    <input >
  </ng-form>
  </div>

Comments

0

You just need to reverse the conversion in the concatenation of the names. When parsing a parameter on ng-submit what you need to convert is the hard-coded string, not the rowId.

would be something like that:

<input ng-model="query" type="text" placeholder="Filter by" autofocus>
<ul class="gNow">
<li ng-repeat="item in selRole.selectRoles | multifilter:query">
    <form name="selRoleForm-{{item.rowId}}" ng-submit="selRole.selectRole('selRoleForm-'+item.rowId)" novalidate>
        <div class="card">
            <p>Card Name: {{item.cardName}}</p>
            <p>.. other form elements here ..</p>
            <p><button type="submit">Select</button></p>
        </div>
    </form>
</li>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.