Duplicate value in multiple textarea while using ng-repeat

siladityamishra
Kilo Contributor

Hi Guys,

We have created multiple textarea field by using ng-repeat, the field are getting display as intended. However while entering a value in one textarea field the value are appearing in other textarea as well, while we are not typing on the other textarea. This may be due to using ng-repeat to display multiple field. We want each and every textarea field to be behave independently.

HTML code:    

<div ng-repeat="approval in data.approvals" class="sp-approval m-b">

          <div class="row">

              <div ng-class="contentColClass">

<div ng-if="!options.portal" class="col-sm-3">

                  <button name="approve" ng-if="approval.state == 'requested'" class="btn btn-primary btn-block" style="border-width:1px;" ng-click="approve(approval.sys_id);">${Approve}</button>

                  <button name="reject" ng-if="approval.state == 'requested'" class="btn btn-default btn-block" ng-click="reject(approval.sys_id);" ng-disabled="approval.task.number.startsWith('RITM') && !data.comment || data.isPosting ">${Reject}</button>

                  <textarea   sn-resize-height="trim"   id="post-input" ng-if="approval.task.number.startsWith('RITM') && approval.state == 'requested'" class="form-control no-resize" ng-model="data.comment" placeholder="${Rejection reason}..." autocomplete="off" ng-change="userTyping(data.comment)"/>

                <span class="input-group-btn" style="vertical-align: buttom">

              </span>

</div>

</div>

</div>

</div>

I have attached a screenshot of the view that we are getting.

Any suggestions or ideas will help me a lot. Capture.PNG

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi



you are binding all the text areas to the same model "data.comment", so when you update one, the other will be updated as well.



You could create a an array as data.comment = [] instead and then map each to a different location in the array



ng-model="data.model[$index]"


View solution in original post

7 REPLIES 7

larstange
Mega Sage

Its a bit difficult to debug, when I don't have it running locally.



In the cllient script if you add this line below line 4 what do you get in the console?



jslog(c.data.comment[x]);


Thanks Lars!



I have used toString(); in-order to convert object.


Akshay37
Mega Guru

Hi,

 

For this you can create one more property inside approval object to store the comment and assign it to

ng-model, in above case such as ng-model="approval.comment" inside your textarea.

 

if you want to access it inside client controller script pass it through any function as a parameter specified in ng-click or ng-change   

 

 

Please Mark it as helpful if it helps you.