AngularJs: Required field validation and highlight for dynamic rows of HTML table with contenteditable

前端 未结 2 836
离开以前
离开以前 2021-01-18 04:00

I have an HTML table as below:


    
               


        
2条回答
  •  广开言路
    2021-01-18 04:50

    The thing is the is not working. Try first with just one and see how you can do it for N columns and N rows correctly.

    When someone clicks save, you can pass the rows array and add a valid/invalid boolean value inside that object, then use ng-class to highlight that cell or not, depending on the result.

    
    
    
    $scope.save = function(rows, columns) {
        rows.forEach(row => {
            if (!row.value || row.value.trim() === '') {
                row.invalid = true;
            } else {
                row.invalid = false;
            }
        })
        alert('please fill table data');
    };
    

    I have modified your fiddle with these changes, I hope you can use it.

    http://jsfiddle.net/4t85gw1z/

提交回复
热议问题