Question: How can I show the validation error using only the ng-model
if I cannot name the form and its elements.
I have a html form to collect credit card details. To prevent the credit card data from touching my server, I cannot name the form elements. So my form looks like:
<form ng-submit="vm.processForm()">
<div class="form-row">
<label>
<span>Card Number</span>
<input type="text" size="20" data-stripe="number" ng-model="vm.number" required>
</label>
</div>
<div class="form-row">
<label>
<span>Expiration (MM/YY)</span>
<input type="text" size="2" data-stripe="exp_month" ng-model="vm.exp_month" required>
</label>
<span> / </span>
<input type="text" size="2" data-stripe="exp_year" ng-model="vm.exp_year" required>
</div>
<div class="form-row">
<label>
<span>CVC</span>
<input type="text" size="4" data-stripe="cvc" ng-model="vm.cvc" required>
</label>
</div>
<input type="submit" class="submit" value="Submit Payment">
</form>
Usually in Angular, I used to check validation using the form elements name, for example like this:
<p ng-show="userForm.creditcard.$error.required">Your credit card number is required.</p>
But since I cannot name the form and its elements, how can I show the validation error using only the ng-model? Because, the following doesn't work:
<p ng-show="vm.number.$error.required">Your credit card number is required.</p>
I am using Angular v1.4.8.
maxlength
andminlength
validation?vm.number.length
should work. Simple, but it did not strike me. The reason I can't use names because adding name would make the user-supplied data in those fields to be passed to my server when the form is submitted. I dont want that since not naming means I no longer need to worry about redacting logs, encrypting cardholder details, or other burdens of PCI compliance.