Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Weird order in form

    Hi, i'm using a datasource to show some data in a Grid, and using a Form to edit, problem is, that i need to use a password validator, but i want it next to the original password field.

    I tried putting the original pass field last in the datasource, and adding the passwordValidatorField after that, but as seen in the image, didn't work.

    Is there a way to add a Field (in this case, the password validator) in a specific position? say, i want the original password field first and the password validator second, and the others fields as they are/get.

    Here's my code.

    Code:
            // grid & form data source
            DataSource dataSource = UserDataSource.getInstance();
    
            final DynamicForm userForm = new DynamicForm();
            userForm.setDataSource(dataSource);
            userForm.setUseAllDataSourceFields(true);
            // we create a header for the form
            HeaderItem header = new HeaderItem();
            header.setDefaultValue(messages.users());
    
            // for the user form we want to have a second password field
            // to validate that there are no user errors when typing the password
    
            // second password field validator
            MatchesFieldValidator validatePassword = new MatchesFieldValidator();
            validatePassword.setOtherField(UserDataSource.PASS_FIELD);
            validatePassword.setErrorMessage(messages.passwordsDontMatch());
            // adding a second pssword field
            PasswordItem passwordField2 = new PasswordItem();
            passwordField2.setName(UserDataSource.PASS_FIELD + "2");
            passwordField2.setTitle(messages.passwordAgain());
            passwordField2.setRequired(false);
            passwordField2.setValidators(validatePassword);
            userForm.setFields(header, passwordField2);
    Attached Files

    #2
    When you set useAllDataSourceFields, each field you specify that is not in the DataSource follows the last field you specified that *is* in the DataSource.

    This sample happens to show exactly what you're trying to do (add a second password field right after the one in the DataSource).

    Comment


      #3
      Hi, thanks for the quick response.

      That's exactly the example we were using to make our form, but as you can see, it displays the validate password field BEFORE the fields in the datasource.

      The validate password is NOT in the datasource, and is showing before the fields that are in the datasource.

      Comment


        #4
        Right, and your mistake is, you didn't refer to the password field from the DataSource before adding the second password field. Specifically, you need to add a PasswordItem with the same name as the DataSource field. You don't need to recapitulate any settings from the DataSource field however - they are inherited.

        Comment


          #5
          Thanks, that did the trick.

          Comment

          Working...
          X