Skip to content

Commit

Permalink
#75 Limitierung der Prüfungsnummern-Eingabe (#79)
Browse files Browse the repository at this point in the history
* add limit of input and only allow numbers as input

* remove usless th: from input type

---------

Co-authored-by: Yanick Minder <[email protected]>
  • Loading branch information
Miguel7373 and kcinay055679 authored Sep 18, 2024
1 parent 61283f9 commit f655ec0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/resources/templates/fragments/exam-number-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<div>
<form action="#" th:action="@{/search}" th:object="${examNumberForm}" method="post">
<label for="examNumber">Prüfungsnummer eingeben*:</label>
<input type="text" name="examNumber" id="examNumber"
placeholder="20202" th:value="*{examNumber}" required>
<input type="text" name="examNumber" id="examNumber" oninput="this.value = this.value.replace(/\D+/g, '')"
placeholder="20202" th:value="*{examNumber}" th:maxlength="5" required>
<button type="submit" id="submitButton">Suchen</button>
<p th:if="${#fields.hasErrors('examNumber')}" th:errors="*{examNumber}">Prüfungsnummer Error</p>
</form>
Expand Down
11 changes: 10 additions & 1 deletion src/test/e2e/cypress/e2e/search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ it('should display error when no exams were found', () => {
});

it('should display error when exam number is invalid', () => {
cy.get('input[type="text"]').type('abc');
cy.get('input[type="text"]').type('123');
cy.get('button').click();
cy.contains('Prüfungsnummer muss 5 Ziffern lang sein');
});
Expand Down Expand Up @@ -81,3 +81,12 @@ it('should rename files to subject-folder they are inside of after downloading',
}
cy.expect(i).to.equal(3)
});


it('should not be able to input more than 5 characters', () => {
cy.get('input[type="text"]').type('110000').should('have.value', '11000');
});

it('should not be able to input other characters', () => {
cy.get('input[type="text"]').type('a2c').should('have.value', '2');
});

0 comments on commit f655ec0

Please sign in to comment.