Password field mandatory

Hello,

How can I make a password field mandatory?
image

I tried

  <passwordField id="passwordField_1" required="true"/>

but doesn’t help.

Please advise!

Hi,

If something doesn’t work, please be more specific about what’s broken. required="true" perfectly works with PasswordField.

40

Gleb

In the sense that Login (Submit) button still works.
image

Because you need to validate this field manually. The same the default fields are validated by the LoginScreen, see com.haulmont.cuba.web.app.login.LoginScreen#doLogin().

Could you be more specific pls? What means to validate manually?
To use an invoke function “login” in this way? However I don’t want to login in the application from my “Enter Key” button.

 public void login() {
        this.doLogin();
    }

 protected void doLogin() {
        String login = (String)this.loginField.getValue();
        String password = this.passwordField.getValue() != null ? (String)this.passwordField.getValue() : "";;
        if (!StringUtils.isEmpty(login) && !StringUtils.isEmpty(password)) {
            try {
                Locale selectedLocale = (Locale)this.localesSelect.getValue();
                this.app.setLocale(selectedLocale);
                if (this.loginByRememberMe && this.webConfig.getRememberMeEnabled()) {
                    this.doLogin(new RememberMeCredentials(login, password, selectedLocale));
                } else {
                    this.doLogin(new LoginPasswordCredentials(login, password, selectedLocale));
                }

                if (this.connection.getSession() != null) {
                    Locale loggedInLocale = this.connection.getSession().getLocale();
                    if (this.globalConfig.getLocaleSelectVisible()) {
                        this.app.addCookie("LAST_LOCALE", loggedInLocale.toLanguageTag());
                    }
                }
            } catch (InternalAuthenticationException var5) {

As far as I understand, you want to prevent a user from login if no key is entered. Event though you define a password field as mandatory, this means nothing for the Submit button, because its implementation checks only the default login and password fields, so you need to extend LoginScreen and provide your own implementation for either login or doLogin methods that will check that the Key field is filled.

I already extended LoginScreen but indeed I have to modify doLogin or Login
methods. Being part of the system I avoided to modify them.
Thank you!