I have table
with ng-repeat
for table rows. I want to make inline editing and validation of data from single row, but it is impossible to use for
I create example with simple validation to your second question:
View:
Id
Firstname
Lastname
{{item.id}}
Submit
Controller:
function MyCtrl($scope) {
$scope.items = [
{
id: 1,
firstName: 'Ivan',
lastName: 'Ivanov',
email: 'email@email.com'
},
{
id: 2,
firstName: 'Petr',
lastName: 'Petrov',
email: 'email@email.com'
}
];
$scope.emailRegExp = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/;
}
Please, see jsfiddle :)
Jsfiddle
For your question in comment about date validation:
I see two ways for do it:
1) In yor controller you create $scope.dateRegExp = "/^\d{2}([./-])\d{2}\1\d{4}$/"
and into the view you using it with ng-pattern="dateRegExp"
2) You can use ng-change=""
directive:
View:
Controller:
$scope.dateInputError = false;
$scope.validateDate = function(date) {
if(//some validation){
$scope.dateInputError = true; //true - it means error style shows
}
};
- 热议问题