This plunker allows you to edit rows in a grid. I have created a new method based on RowEditCtrl to insert a new row but am having trouble with the validation.
When I insert a new row, the form is "pristine and valid". In the insert method, I need to call $scope.$broadcast('schemaFormValidate')
which will validate the form and form.$valid
will be false. Ideally, I would like to call this check from ng-show
on the save button so the button does not appear until the form is ok.
The problem is, I don't understand or know how to get the schema-form $scope
in this RowEditCtrl
method and cannot get the form to be invalid before the user has typed anything.
function RowEditCtrl($modalInstance, PersonSchema, grid, row) {
var vm = this;
vm.schema = PersonSchema;
vm.entity = angular.copy(row.entity);
vm.form = [
'name',
'company',
'phone',
{
'key': 'address.city',
'title': 'City'
},
];
vm.save = save;
function save() {
// Copy row values over
row.entity = angular.extend(row.entity, vm.entity);
$modalInstance.close(row.entity);
}
}