Skip to content

Commit ba1ff50

Browse files
authored
feat: allow setting error message for login fields (#5041)
1 parent 64d5d60 commit ba1ff50

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎vaadin-login-flow-parent/vaadin-login-flow/src/main/java/com/vaadin/flow/component/login/LoginI18n.java‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ public static class ErrorMessage implements Serializable {
252252
private String title;
253253
private String message;
254254

255+
private String username;
256+
private String password;
257+
255258
/**
256259
* @return current value for the title property
257260
*/
@@ -281,6 +284,40 @@ public String getMessage() {
281284
public void setMessage(String message) {
282285
this.message = message;
283286
}
287+
288+
/**
289+
* @return current value for the username property
290+
*/
291+
public String getUsername() {
292+
return username;
293+
}
294+
295+
/**
296+
* Sets the error message for the username field
297+
*
298+
* @param username
299+
* new value for the username property
300+
*/
301+
public void setUsername(String username) {
302+
this.username = username;
303+
}
304+
305+
/**
306+
* @return current value for the password property
307+
*/
308+
public String getPassword() {
309+
return password;
310+
}
311+
312+
/**
313+
* Sets the error message for the password field
314+
*
315+
* @param password
316+
* new value for the password property
317+
*/
318+
public void setPassword(String password) {
319+
this.password = password;
320+
}
284321
}
285322

286323
}

‎vaadin-login-flow-parent/vaadin-login-flow/src/main/resources/com/vaadin/flow/component/login/i18n.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
},
99
"errorMessage": {
1010
"title": "Incorrect username or password",
11-
"message": "Check that you have entered the correct username and password and try again."
11+
"message": "Check that you have entered the correct username and password and try again.",
12+
"username": "Username is required",
13+
"password": "Password is required"
1214
}
1315
}

‎vaadin-login-flow-parent/vaadin-login-flow/src/test/java/com/vaadin/flow/component/login/LoginFormI18nTest.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public void createDefault() {
2222
"Check that you have entered the correct username and password and try again.",
2323
i18n.getErrorMessage().getMessage());
2424

25-
Assert.assertEquals(null, i18n.getAdditionalInformation());
25+
Assert.assertEquals("Username is required",
26+
i18n.getErrorMessage().getUsername());
27+
Assert.assertEquals("Password is required",
28+
i18n.getErrorMessage().getPassword());
29+
30+
Assert.assertNull(i18n.getAdditionalInformation());
2631
}
2732
}

0 commit comments

Comments
 (0)