I have 4 angular forms, and a save button
save button
<div class="col-sm-2">
<button class="btn btn-sm btn-primary pull-right admin-hide mb10" ng-show="showSaveBtn == true" ng-click="checkSaveBtn()">Save</button>
</div>
4 forms
{{-- WiFi Includes --}}
@if($section == "private")
<div ng-form="private2" name="p24Form" ng-show="freqSelect == '2.4'" novalidate>
@include('views.settings.wifi.private2')
</div>
<div ng-form="private5" name="p50Form" ng-show="freqSelect == '5'" novalidate>
@include('views.settings.wifi.private5')
</div>
@elseif($section == "guest")
<div ng-form="guest2" name="g24Form" ng-show="freqSelect == '2.4'" novalidate>
@include('views.settings.wifi.guest2')
</div>
<div ng-form="guest5" name="g50Form" ng-show="freqSelect == '5'" novalidate>
@include('views.settings.wifi.guest5')
</div>
@endif
I am trying to detect and show my save button as soon as one of those 4 forms got changed.
I've tried
$scope.showSaveBtn = false;
$scope.checkSaveBtn = function() {
if (
$scope.p24Form.$dirty ||
$scope.g24Form.$dirty ||
$scope.p50Form.$dirty ||
$scope.g50Form.$dirty
) {
$scope.showSaveBtn = true;
}else{
$scope.showSaveBtn = false;
}
}
console.info('$scope.showSaveBtn = ', $scope.showSaveBtn);
Result
$scope.showSaveBtn
kept returning false ...
Why does it keep returning false ? What did I do wrong ?
How would one go about and debug this further?
Note
ngChange-like functionality for the entire form
is not answering my post. According to the link, people using tag, but in my case I used tag with ng-form
attribute, the way we use to check it might be slightly different.