1

I have textarea where user can enter multiple source:Ids separated by comma;i need to iterate through each source:Id and validate each of them and highlight only the wrong source:Id formats in red font. I wrote a ng-change fn which iterates through all the inputs and give me the incorrect one. Any idea how to change the font color for that wrong input from controller?

             $scope.memberArray = $scope.memberList.split(",");
                for (var i = 0; i < $scope.memberArray.length; i++) {
                    $scope.memberIDArray = [];
                    //validate source:Id format
                    if ($scope.memberArray[i].match(format)) {
                        continue;
                    } else {
                        //TODO change the $scope.memberArray[i] element font color to red
                      //so that  it highlights in red in the html
                      }
                  
                  }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<textarea autofocus ng-model="memberList" rows="8" cols="80"
                                                ng-change="checkInput()"></textarea>
Josip Ivic
  • 3,639
  • 9
  • 39
  • 57
Bidisha
  • 287
  • 1
  • 5
  • 16
  • http://stackoverflow.com/questions/4845813/multicolor-text-highlighting-in-a-textarea-or-text-input – Saar Oct 05 '15 at 19:12
  • its posted ...simple textarea with ng-model – Bidisha Oct 05 '15 at 19:22
  • You didn't post another important part: how you define input elements in HTML. – dfsq Oct 05 '15 at 19:24
  • I misunderstood the original question. It is much clearer now after your last edit. You cannot style parts of a textarea. You can use a content editable control instead. http://stackoverflow.com/questions/4705848/rendering-html-inside-textarea – masimplo Oct 05 '15 at 19:31
  • You will need to implement your own custom directive for this functionality because it is not possible to style only parts of textarea. – Dejan Bogatinovski Oct 05 '15 at 19:39
  • Thanks @mxa055 ...... – Bidisha Oct 05 '15 at 19:42
  • Thanks @Dejan Bogatinovski – Bidisha Oct 05 '15 at 19:42
  • @mxa055 is it possible to select or focus if not style a part of the textarea through angularjs? – Bidisha Oct 05 '15 at 19:46
  • @Bidisha TextArea possibilities are not specific to angularjs, more HTML. Angularjs does not provide any helpers for doing such operations if that is what you are looking for. That being said, inputs and textareas have an API to control selected text https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Property/selectionStart – masimplo Oct 05 '15 at 19:50

0 Answers0