This Plunker demo allows for editing rows in a grid. A new method has been implemented based on RowEditCtrl to insert a new row, but there are issues with validation.
Upon inserting a new row, the form initially appears as "pristine and valid". To validate the form,
$scope.$broadcast('schemaFormValidate')
must be called within the insert method, resulting in form.$valid
being false. It is desired to trigger this validation check using ng-show
on the save button so that it only appears when the form is deemed okay.
The challenge lies in accessing the schema-form $scope
within the RowEditCtrl
method and setting the form as invalid before any user input.
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);
}
}