Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have table with input=text fields, and when some of fields has id 'four' I need to disable this whole row. For this I try to use this function:

  $scope.disableIfRowHasFour = function(row){
    var result = row.filter(function(field){
      return field.id === 'four';
    })

    return result.length !== 0;
  };

and in html:

<tr ng-disabled='disableIfRowHasFour(row)' ng-repeat='row in tableFields'>
  <td ng-repeat='field in row'>
    <input type="text" value='{{field.value}}'>
  </td>
</tr>

and in devtools I see that row is disabled, but inputs in this row - not.

<tr ng-disabled="disableIfRowHasFour(row)" ng-repeat="row in tableFields" class="ng-scope" disabled="disabled">

where I'm wrong? I expect that all items in a row will be disabled..Plnkr example

share|improve this question
1  
You should add the ng-disabled tag on the input instead of the tr – Juanín 21 hours ago
    
yes, but how can I disabled all fields in a row, if id=four has only 1 input? – YoroDiallo 21 hours ago
1  
add ng-disabled='disableIfRowHasFour(row)' on the input. It should work – Juanín 21 hours ago
    
oh!)) you right) thx a lot – YoroDiallo 21 hours ago
    
Look my answer, you can use ng-init to prevent multiple calls. – rogeriolino 21 hours ago
up vote 1 down vote accepted

In the tr tag use ng-init to initialize a variable with disabled value:

<tr ng-init='rowDisabled=disableIfRowHasFour(row)' ng-repeat='row in tableFields'>

And in the inputs you add ng-disabled:

<input type="text" value='{{field.value}}' ng-disabled="rowDisabled">
share|improve this answer
    
I think this wouldn't work because rowDisabled would be a variable shared among all the rows and therefore it would be true if the last one has four and false if the last one has something different than four. But, I'm not sure about the scope of the variable. – Juanín 21 hours ago
1  
each element in ng-repeat has its own scope, hence it will work – entre 21 hours ago
    
yes, it works too, thx! is this faster then "ng-disabled='disableIfRowHasFour(row)' on the input"? or it does no matter? – YoroDiallo 21 hours ago
    
Storing the value in a variable prevent you to invoke the disableIfRowHasFour function on each input, saving processing. – rogeriolino 21 hours ago
    
I see, thx for your help! – YoroDiallo 21 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.