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);
}
}
I was able to access
$scopeinRowEditCtrlby passing$scopeintoeditRow's$modal.opencontroller. See my fork of the original the plunkr here: http://next.plnkr.co/edit/NiwF12BLJQyD6CkuHere are the relevant changes:
...
...
When I do this
console.logof$scope.$broadcast('schemaFormValidate')within the modal'ssavefunction it seems to be working. Or, at least$scopeis defined and $broadcast callable. Apologies if this does not address the question well enough, I am not familiar withschemaFormValidate.