Click here to Skip to main content
15,918,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
JavaScript
///<reference path="../Scripts/angular.min.js" />
///<reference path="../Scripts/angular-route.min.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) {

//Fonction : Type de contrat (IS/OS)
$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;
};

//Fonction : Date de signature de l’offre / Type Revue ESR
$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 :
HTML
<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 ...
Posted
Updated 9-May-17 5:29am
v3

1 solution

"Undefined" is javascript for an object that doesn't exist, or null in other languages.

You're trying to get/set a property value on an object that doesn't exist. Somewhere in your code you tried to get an instance of an object or failed to create an object and tried to use it without checking to see if it really exists or not.
 
Share this answer
 
Comments
Saad Hamani 9-May-17 10:46am    
I've edited my question, and added my need and SupportDemande.cshtml
Dave Kreskowiak 9-May-17 10:56am    
OK, and my answer doesn't change. This is where YOUR debugging skills come in. I can't do this for you as I don't have the code, the data it uses, nor the time to do your job for you.
Saad Hamani 9-May-17 11:22am    
http://plnkr.co/edit/Y216fRSgABRKAA04XSoS
Dave Kreskowiak 9-May-17 11:32am    
What's that? I'm not clicking it and I already told you I don't have time to do your job for you. I've told you what's going wrong. It's up to YOU to find out why that object is null.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900