Hello,
My need is that I want the input "Date de signature de l’offre" to be marked "required" if the option "E - Signature du contrat" is selected.
I do not know what the problem is, it seems to me that everything is okay. But it shows me the following error:
TypeError: Cannot read property 'typeRevueESR' of undefined at Scope.SupportDemandeCtrl.$scope.matchSelectedTypeRevueESR (SupportDemandeApp.js:70)
Here is the code on
Plunker
SupportDemandeApp.js :
var supportDemandeApp = angular.module('supportDemandeApp', ['ngMessages']);
supportDemandeApp.controller('SupportDemandeCtrl', ['$scope', '$filter', SupportDemandeCtrl]);
supportDemandeApp.run(function ($rootScope) {
$rootScope.typeOf = function (value) {
return typeof value;
};
})
supportDemandeApp.directive('stringToNumber', function () {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
ngModel.$parsers.push(function (value) {
return '' + value;
});
ngModel.$formatters.push(function (value) {
return parseFloat(value);
});
}
};
});
function SupportDemandeCtrl($scope, $filter) {
$scope.typeContrat = function () {
$scope.typesContrat = ['Niv.I - Impartition IMS',
'Niv.II - Impartition TMA / AMS',
'Niv.III - Projet',
'Niv.IV - Impartition BPO',
'Multi - Tiers avec Impartition',
'Multi-Tiers CS & Projet',
'Vente de licence ou produit sans services ni modification'
];
$scope.selectedTypeContrat = {};
};
$scope.matchSelectedTypeContrat = function () {
if (($scope.selectedTypeContrat.typeContrat === 'Niv.I - Impartition IMS') ||
($scope.selectedTypeContrat.typeContrat === 'Niv.II - Impartition TMA / AMS') ||
($scope.selectedTypeContrat.typeContrat === 'Niv.IV - Impartition BPO') ||
($scope.selectedTypeContrat.typeContrat === 'Multi-Tiers avec Impartition'))
return true;
else
return false;
};
$scope.typeRevueESR = function () {
$scope.typesRevueESR = ["A - Faire une offre ou non",
"B - Stratégie de l'offre",
"A/B",
"C - Soumission de l'offre",
"A/B/C",
"E - Signature du contrat"
];
$scope.selectedTypeRevueESR = {};
};
$scope.matchSelectedTypeRevueESR = function () {
if ($scope.selectedTypeRevueESR.typeRevueESR === 'E - Signature du contrat')
return true;
else
return false;
};
}
SupportDemande.cshtml :
<script src="~/ScriptsJS/SupportDemande.js" type="text/javascript"></script>
<script src="~/ScriptsJS/SupportDemandeApp.js"></script>
<div ng-app="supportDemandeApp" ng-controller="SupportDemandeCtrl">
<form class="form-horizontal" id="supportDemandeForm" name="supportDemandeForm" method="post" ng-submit="validationSupportDemande(supportDemandeForm.$valid)" novalidate>
<fieldset>
<div class="form-group">
<label for="selectTypeRevue" class="col-lg-2 control-label">Type de revue à réaliser<span style="color:red"> *</span></label>
<div class="col-lg-10">
<select class="form-control" id="selectTypeRevue" name="selectTypeRevue" ng-model="selectedTypeRevue" required>
<option disabled hidden selected></option>
<option ng-option>ESR</option>
<option ng-option>SSR</option>
</select>
</div>
<div class="form-group" ng-if="selectedTypeRevue == 'ESR'">
<label for="selectTypeRevueESR" class="col-lg-2 control-label">Type de revue ESR à réaliser<span style="color:red"> *</span></label>
<div class="col-lg-10">
<select class="form-control" id="selectTypeRevueESR" name="selectTypeRevueESR" ng-model="selectedTypeRevueESR.typeRevueESR" ng-init="typeRevueESR()" ng-options="typeRevueESR for typeRevueESR in typesRevueESR" required></select>
</div>
<div class="form-group has-warning" ng-required="matchSelectedTypeRevueESR()">
<label for="inputDateSignatureOffre" class="col-lg-2 control-label">Date de signature de l’offre</label>
<div class="col-lg-10">
<input type="date" class="form-control" id="inputDateSignatureOffre" name="inputDateSignatureOffre" ng-model="inputDateSignatureOffre">
</div>
</fieldset>
</form>
</div>
What I have tried:
I've tried to add 'factoryService' & '$scope' as array items ...