2
I wanted to make two fields select one for the month and one for the year to use as expiration dates of a card, but wanted it to be generated dynamically and that when selecting the year 2017 for example appears only the months remaining to end the year that in the case on today date would appear only December. I only made a basic structure in html.
<div class="col-md-4 col-lg-4 col-sm-12 col-xs-12">
<label>Mês</label>
<select required ng-model="customer.monthCard">
<option value="01">Janeiro</option>
<option value="02">Favereiro </option>
<option value="03">Março</option>
<option value="04">Abril</option>
<option value="05">Maio</option>
<option value="06">Junho</option>
<option value="07">Julho</option>
<option value="08">Agosto</option>
<option value="09">Setembro</option>
<option value="10">Outubro</option>
<option value="11">Novembro</option>
<option value="12">Dezembro</option>
</select>
</div>
<div class="col-md-3 col-lg-3 col-sm-12 col-xs-12">
<label>Ano</label>
<select required ng-model="customer.yearCard">
<option value="18"> 2018</option>
<option value="19"> 2019</option>
<option value="20"> 2020</option>
<option value="21"> 2021</option>
</select>
</div>
For security reasons, I advise you to do this verification through the programming you use in the dynamic language, for example: PHP. Because anyone with knowledge in the browser console can remove this check.
– Carlos Andrade
My idea would be through Avascript and Angular generate the years (until 2027 for example) when loading the page and the current year receives only the months that come after the current month and then load dynamically on the page. The validations will all be done on the server, it would be something more for interface same.
– Erick Zanetti
@Carlosandrade, the check could very well be done on the frontend, provided that in the backend there is a check of type: If the date informed is not a date, or is earlier than today’s date, return error
– MarceloBoni
Yes, of course. So that in the backend also have. I find it difficult to do two types of verification, while one would be enough. But every case is a case.
– Carlos Andrade